From 59329f3402aea201c1f0bc99dc8153accda69193 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 7 Oct 2026 13:36:21 +0200 Subject: [PATCH] libssh2_userauth_keyboard_interactive_ex.md: fix allocator requirement Prior to this patch, the documentation stated that the `.text` buffers filled by the API caller are "free(3)d" by libssh2, referring to the default system deallocator. In reality however, libssh2 was using `SSH2_FREE*()` to free these buffers, respecting custom allocators, if set by the user via `libssh2_session_init_ex()`. libssh2 behaved this way since the initial implementation committed in da653774aa57fc234d978cf03d3b38d674b00e12 2005-06-11, v0.11 Later, examples were added that use `strdup()` to allocate, which was (and is) accurate because they do not use a custom allocator: 9a1ce06e31d0ce64f484f6d91c4d84c6215f1195 2007-07-22 Then, when the documentation landed, it incorrectly documented `free(3)`, perhaps basing it on the examples added earlier: d4aa801f6f5b3eaeac3d87125f4b48d60b91ebaa 2008-03-08 I assume that callers overriding the custom allocators are more likely to have fixed their code to adhere with how libssh2 actually behaved, rather than believing the documentation and live with an allocator mismatch for all these years. Therefore I think this is a documentation error, and this patch addresses this. Reported-by: Makise Kurisu Fixes GHSA-p6p8-66vc-3f24 Reverts ce631aafe14d6303103dee1ee22b7091ecc4af81 #2659 Follow-up to d4aa801f6f5b3eaeac3d87125f4b48d60b91ebaa Follow-up to da653774aa57fc234d978cf03d3b38d674b00e12 Closes #2661 --- docs/libssh2_userauth_keyboard_interactive_ex.md | 11 ++++++----- include/libssh2.h | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/libssh2_userauth_keyboard_interactive_ex.md b/docs/libssh2_userauth_keyboard_interactive_ex.md index 87eff43c..709458d6 100644 --- a/docs/libssh2_userauth_keyboard_interactive_ex.md +++ b/docs/libssh2_userauth_keyboard_interactive_ex.md @@ -36,11 +36,12 @@ for. *username_len* - Length of username parameter. *response_callback* - As authentication proceeds, the host issues several -(1 or more) challenges and requires responses. This callback is called at -this moment. The callback is responsible to obtain responses for the -challenges, fill the provided data structure and then return -control. Responses are sent to the host. String values are free(3)ed -by the library. The callback prototype must match this: +(1 or more) challenges and requires responses. This callback is called at this +moment. The callback is responsible to obtain responses for the challenges, +fill the provided data structure and then return control. Use the custom +LIBSSH2_ALLOC_FUNC (or, if not set, the default system allocator) to allocate +memory for the `text` field. Responses are sent to the host. The callback +prototype must match this: ~~~c void response(const char *name, diff --git a/include/libssh2.h b/include/libssh2.h index 267cf3a5..c14e3a56 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -218,14 +218,14 @@ typedef off_t libssh2_struct_stat_size; #endif typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT { - unsigned char *text; /* FIXME: require LIBSSH2_ALLOC_FUNC */ + unsigned char *text; size_t length; unsigned char echo; } LIBSSH2_USERAUTH_KBDINT_PROMPT; typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE { - char *text; /* FIXME: require LIBSSH2_ALLOC_FUNC */ + char *text; unsigned int length; /* FIXME: change type to size_t */ } LIBSSH2_USERAUTH_KBDINT_RESPONSE;