Skip to content

Commit 10d8404

Browse files
committed
libssh2: use custom memory functions
Because of how libssh2_userauth_keyboard_interactive_ex() works: the libcurl callback allocates memory that is later free()d by libssh2, we must set the custom memory functions. Reverts 8b5f100 Ref: libssh2/libssh2#1078 Closes curl#11235
1 parent bfa7006 commit 10d8404

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/vssh/libssh2.c

+3-10
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@
100100

101101
/* Local functions: */
102102
static const char *sftp_libssh2_strerror(unsigned long err);
103-
#ifdef CURL_LIBSSH2_DEBUG
104103
static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc);
105104
static LIBSSH2_REALLOC_FUNC(my_libssh2_realloc);
106105
static LIBSSH2_FREE_FUNC(my_libssh2_free);
107-
#endif
108106
static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data);
109107
static CURLcode ssh_connect(struct Curl_easy *data, bool *done);
110108
static CURLcode ssh_multi_statemach(struct Curl_easy *data, bool *done);
@@ -284,8 +282,6 @@ static CURLcode libssh2_session_error_to_CURLE(int err)
284282
return CURLE_SSH;
285283
}
286284

287-
#ifdef CURL_LIBSSH2_DEBUG
288-
289285
static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc)
290286
{
291287
(void)abstract; /* arg not used */
@@ -305,8 +301,6 @@ static LIBSSH2_FREE_FUNC(my_libssh2_free)
305301
free(ptr);
306302
}
307303

308-
#endif
309-
310304
/*
311305
* SSH State machine related code
312306
*/
@@ -3268,13 +3262,12 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)
32683262
sock = conn->sock[FIRSTSOCKET];
32693263
#endif /* CURL_LIBSSH2_DEBUG */
32703264

3271-
#ifdef CURL_LIBSSH2_DEBUG
3265+
/* libcurl MUST to set custom memory functions so that the kbd_callback
3266+
funciton's memory allocations can be properled freed */
32723267
sshc->ssh_session = libssh2_session_init_ex(my_libssh2_malloc,
32733268
my_libssh2_free,
32743269
my_libssh2_realloc, data);
3275-
#else
3276-
sshc->ssh_session = libssh2_session_init_ex(NULL, NULL, NULL, data);
3277-
#endif
3270+
32783271
if(!sshc->ssh_session) {
32793272
failf(data, "Failure initialising ssh session");
32803273
return CURLE_FAILED_INIT;

0 commit comments

Comments
 (0)