Skip to content

wincng: avoid pointer cast in wcng_ecdsa_new_private_parse() - #2426

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:wincng-use-new-get-chars-api
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:wincng-use-new-get-chars-api

Conversation

@vszakats

Copy link
Copy Markdown
Member

By using the recently added non-unsigned internal API variant.

Follow-up to 907fe84 #2424
Follow-up to 3e72343 #1315

By using the recently added non-unsigned internal API variant.

Follow-up to 907fe84 libssh2#2424
Follow-up to 3e72343 libssh2#1315
Copilot AI review requested due to automatic review settings July 24, 2026 11:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ...) with ssh2_get_chars(...) when reading the ECDSA key type.
Comments suppressed due to low confidence (1)

src/wincng.c:2370

  • ssh2_get_chars() (like ssh2_get_string()) returns a length-delimited SSH “string” that is not NUL-terminated, but wcng_ecdsa_curve_type_from_name() uses strcmp(). 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 calling wcng_ecdsa_curve_type_from_name(), or changing the helper to accept a length and use memcmp().
    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.

@vszakats vszakats closed this in d4d068f Jul 24, 2026
@vszakats
vszakats deleted the wincng-use-new-get-chars-api branch July 24, 2026 12:22
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants