]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
libssh2: set length to 0 if strdup failed
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 27 Mar 2024 23:38:09 +0000 (00:38 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 28 Mar 2024 10:21:44 +0000 (11:21 +0100)
Internally, libssh2 dereferences the NULL pointer if length is non-zero.
The callback function cannot return the error condition, so at least
prevent subsequent crash.

Closes #13213

lib/vssh/libssh2.c

index 3cfbe126c69df39bb6c925894247f5bb48107e13..7d8d5f46571e9f23ab351d9b5fd0bd8232ee4e27 100644 (file)
@@ -201,7 +201,8 @@ kbd_callback(const char *name, int name_len, const char *instruction,
   if(num_prompts == 1) {
     struct connectdata *conn = data->conn;
     responses[0].text = strdup(conn->passwd);
-    responses[0].length = curlx_uztoui(strlen(conn->passwd));
+    responses[0].length =
+      responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd));
   }
   (void)prompts;
 } /* kbd_callback */