Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the WinCNG ECDSA code paths to avoid leaking resources when allocating the ECDSA context fails (OOM), by allocating context objects earlier and ensuring error cleanups null out freed output pointers.
Changes:
- Allocate
ssh2_ecdsa_ctx/wcng_ecdsa_ctxearlier inssh2_ecdsa_create_key(),ssh2_ecdsa_curve_name_with_octal_new(), andwcng_parse_ecdsa_privatekey()to prevent downstream resource leaks on OOM. - Improve error cleanup to free allocated contexts and set output pointers to
NULLon failure.
Comments suppressed due to low confidence (1)
src/wincng.c:2168
ssh2_ecdsa_curve_name_with_octal_new()infers the curve from the encoded point length (wcng_ecdsa_decode_uncompressed_point()setspublickey.curve), but it never verifies that this matches the caller-providedcurveargument. This can accept malformed/contradictory host keys and then store a potentially wrongec_ctx->curve, which later drives hash/signature sizing inssh2_ecdsa_verify()viassh2_ecdsa_get_curve_type(ec_ctx). Add an explicit check to reject mismatches before importing the key.
result = wcng_ecdsa_decode_uncompressed_point(
publickey_encoded,
publickey_encoded_len,
&publickey);
if(result != LIBSSH2_ERROR_NONE)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jul 14, 2026
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.
Ref: #2300 (comment)
Ref: #2301 (comment)
Follow-up to 3e72343 #1315