Repository navigation
Conversation
By using the recently added non-unsigned internal API variant. Follow-up to 907fe84 libssh2#2424 Follow-up to 3e72343 libssh2#1315
There was a problem hiding this comment.
Pull request overview
This PR updates the WinCNG ECDSA private-key parsing path to use the newer internal API that returns char * buffers, removing the need for an (unsigned char **)&keytype pointer cast in wcng_ecdsa_new_private_parse().
Changes:
- Replace
ssh2_get_string(... (unsigned char **)&keytype ...)withssh2_get_chars(...)when reading the ECDSA key type.
Comments suppressed due to low confidence (1)
src/wincng.c:2370
ssh2_get_chars()(likessh2_get_string()) returns a length-delimited SSH “string” that is not NUL-terminated, butwcng_ecdsa_curve_type_from_name()usesstrcmp(). This can read past the end of the keytype field (UB / potential crash) when parsing OpenSSH private key blobs. Consider NUL-terminating a temporary copy before callingwcng_ecdsa_curve_type_from_name(), or changing the helper to accept a length and usememcmp().
result = ssh2_get_chars(&data_buffer, &keytype, &keytype_len);
if(result != LIBSSH2_ERROR_NONE)
goto cleanup;
result = wcng_ecdsa_curve_type_from_name(keytype, &curve_type);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1 of 3 tasks
vszakats
added a commit
that referenced
this pull request
Jul 24, 2026
…arsing Before this patch some checks were using `strcmp()` on received/read buffers that may not necessarily have a null-terminator. Fix by always using the buffer length returned by the buffer reader, compare this length with the expected one, and use `memcmp()` to verify the content. When reading ECDSA/ED25519 OpenSSH-formatted keys in `mbed_parse_openssh_key()`, `ossl_key_from_openssh()`, OpenSSL's `ssh2_sk_pubkey()`, `pem_parse_data_openssh()`, `wcng_ecdsa_new_private_parse()`. Introduce `SSH2_IS_LITERAL()` macro to hide the delicate logic of comparing a non-null-terminated memory buffer with a string literal. Reported by Copilot Bug: #2420 (comment) Bug: #2420 (review) Bug: #2426 (review) Bug: #2420 (comment) Bug: #2420 (comment) Ref: 0fcb662 #2403 Closes #2421
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.
By using the recently added non-unsigned internal API variant.
Follow-up to 907fe84 #2424
Follow-up to 3e72343 #1315