From dade304c47087629daaabec2a71aed40af1b2d87 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Wed, 25 May 2011 22:39:25 +0200
Subject: [PATCH] userauth_keyboard_interactive: skip code on zero length auth

---
 src/userauth.c |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/userauth.c b/src/userauth.c
index 976d5fa..abed8e4 100644
--- a/src/userauth.c
+++ b/src/userauth.c
@@ -1,6 +1,6 @@
 /* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
  * Copyright (c) 2005 Mikhail Gusarov <dottedmag@dottedmag.net>
- * Copyright (c) 2009-2010 by Daniel Stenberg
+ * Copyright (c) 2009-2011 by Daniel Stenberg
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms,
@@ -1453,17 +1453,21 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
             /* string    name (ISO-10646 UTF-8) */
             session->userauth_kybd_auth_name_len = _libssh2_ntohu32(s);
             s += 4;
-            session->userauth_kybd_auth_name =
-                LIBSSH2_ALLOC(session, session->userauth_kybd_auth_name_len);
-            if (!session->userauth_kybd_auth_name) {
-                _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
-                               "Unable to allocate memory for "
-                               "keyboard-interactive 'name' request field");
-                goto cleanup;
+            if(session->userauth_kybd_auth_name_len) {
+                session->userauth_kybd_auth_name =
+                    LIBSSH2_ALLOC(session,
+                                  session->userauth_kybd_auth_name_len);
+                if (!session->userauth_kybd_auth_name) {
+                    _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
+                                   "Unable to allocate memory for "
+                                   "keyboard-interactive 'name' "
+                                   "request field");
+                    goto cleanup;
+                }
+                memcpy(session->userauth_kybd_auth_name, s,
+                       session->userauth_kybd_auth_name_len);
+                s += session->userauth_kybd_auth_name_len;
             }
-            memcpy(session->userauth_kybd_auth_name, s,
-                   session->userauth_kybd_auth_name_len);
-            s += session->userauth_kybd_auth_name_len;
 
             /* string    instruction (ISO-10646 UTF-8) */
             session->userauth_kybd_auth_instruction_len = _libssh2_ntohu32(s);
-- 
1.7.5.1

