Repository navigation
Conversation
bagder
added a commit
that referenced
this pull request
Sep 19, 2025
We used to treat 0 as "call strlen() to get the length" for curlx_base64_encode, but it turns out this is rather fragile as we easily do the mistake of passing in zero when the data is actually not there and then calling strlen() is wrong. Force the caller to pass in the correct size. A zero length input string now returns a zero length output and a NULL pointer. Closes #18617
bagder
force-pushed
the
bagder/base64-zero-length
branch
from
September 19, 2025 12:07
cfc7f62 to
680fecd
Compare
We used to treat 0 as "call strlen() to get the length" for curlx_base64_encode, but it turns out this is rather fragile as we easily do the mistake of passing in zero when the data is actually not there and then calling strlen() is wrong. Force the caller to pass in the correct size. A zero length input string now returns a zero length output and a NULL pointer. Closes #18617
bagder
force-pushed
the
bagder/base64-zero-length
branch
from
September 19, 2025 12:32
26cc180 to
e5e65ab
Compare
bagder
marked this pull request as ready for review
September 19, 2025 12:34
1 task done
vszakats
added a commit
to vszakats/libssh2
that referenced
this pull request
Jul 20, 2026
…ownhost_add*()` To apply the same fix made earlier to `ssh2_base64_encode()`, but this one level up in the call chain. This is stricly speaking an incompatible change, but because the automatic-strlen behavior was never documented for these functions, it required a valid `keylen` value be passed, and because the fallback feature is fragile, potentially unsafe, I propose this. Replace by returning `LIBSSH2_ERROR_BAD_USE` if zero `keylen` is passed. Refs: https://github.com/libssh2/libssh2/pull/2363/files#diff-5182b571dc174e7b59106f0ea398a54784a0eb6c32eb95b9952cfa1aca893a71R866 curl/curl@5e2d4d7 curl/curl#18617 Follow-up to 102e444 libssh2#2363 Follow-up to d1c0e14 libssh2#1641
vszakats
added a commit
to libssh2/libssh2
that referenced
this pull request
Jul 20, 2026
…ownhost_add*()` To complement/replace similar fixes made earlier to `ssh2_base64_encode()` and `knownhost_line()`, respectively. Until libssh2 1.11.1, `libssh2_knownhost_add*()` public APIs had a special behavior when they received `keylen == 0` argument. They automatically determined the length of the `key` buffer via `strlen()`. When passing zero length either on purpose or by accident, it could result in an OOB read if the buffer's actual length was zero. (Such case could also happen within libssh2's own code.) This behavior was not documented on the man page, but the public `libssh2.h` header mentioned it in comments. Earlier patch #1641 dropped this behavior for one codepath, which was a breaking change, arguably for the better. This patch fixes the remaining codepath and removes this behavior from these functions completely. They now return `LIBSSH2_ERROR_BAD_USE` when called with a zero `keylen` argument, with an explanatory error string. Recommended fix is passing `key` buffer length, or `strlen()` it at the call site if the buffer is null-terminated, and making sure the buffer is non-empty. Refs: https://github.com/libssh2/libssh2/pull/2363/files#diff-5182b571dc174e7b59106f0ea398a54784a0eb6c32eb95b9952cfa1aca893a71R866 curl/curl@5e2d4d7 curl/curl#18617 Follow-up to 102e444 #2363 Follow-up to d1c0e14 #1641 Follow-up to 4b991b2 Closes #2364
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We used to treat 0 as "call strlen() to get the length" for curlx_base64_encode, but it turns out this is rather fragile as we easily do the mistake of passing in zero when the data is actually not there and then calling strlen() is wrong.
Force the caller to pass in the correct size. Encoding a zero length string now returns a zero length output and a NULL pointer.