]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
libssh2: allocate libssh2-friendly memory in kbd_callback
authorDaniel Stenberg <daniel@haxx.se>
Thu, 16 Apr 2026 08:09:59 +0000 (10:09 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 16 Apr 2026 08:35:32 +0000 (10:35 +0200)
The function libssh2_userauth_keyboard_interactive_ex() calls the
callback and is documented to call free() on the memory returned to
libssh2 from the callback. libcurl can therefore not use the regular
curlx_strdup() for this, as that is not compatible in debug builds or
when curl_global_init_mem() is used.

Fixes #21336
Closes #21338

lib/vssh/libssh2.c

index e4d35bbdcf12f5a0439a5167b3680957384b7871..4e2a72269ff57d54cdc0c0bca0f9a3cb7264e22f 100644 (file)
@@ -148,7 +148,9 @@ static void kbd_callback(const char *name, int name_len,
 #endif /* CURL_LIBSSH2_DEBUG */
   if(num_prompts == 1) {
     struct connectdata *conn = data->conn;
-    responses[0].text = curlx_strdup(conn->passwd);
+    /* this function must allocate memory that can be freed by libssh2, which
+       uses the LIBSSH2_FREE_FUNC callback */
+    responses[0].text = Curl_cstrdup(conn->passwd);
     responses[0].length =
       responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd));
   }