Skip to content

wincng: fix ECC private key blob allocation size - #2631

Closed
abdul-khaliq-khalid wants to merge 1 commit into
libssh2:masterfrom
abdul-khaliq-khalid:wincng-ecc-priv-blob-size
Closed

abdul-khaliq-khalid wants to merge 1 commit into
libssh2:masterfrom
abdul-khaliq-khalid:wincng-ecc-priv-blob-size

Conversation

@abdul-khaliq-khalid

@abdul-khaliq-khalid abdul-khaliq-khalid commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

wcng_privatekey_from_point() sizes the ECC private-key blob with sizeof(BCRYPT_ECCPRIVATE_BLOB), but that name is the wide blob-type string L"ECCPRIVATEBLOB", not a struct, so the sizeof measures the string (30 bytes on Windows) rather than the 8-byte BCRYPT_ECCKEY_BLOB header. The three memcpy offsets right below it, and the public-key sibling wcng_publickey_from_point(), already use sizeof(BCRYPT_ECCKEY_BLOB), so the buffer ends up oversized and its uninitialized tail is handed to BCryptImportKeyPair() with an inflated cbInput. This is on the path that loads an OpenSSH-format ECDSA private key through libssh2_userauth_publickey_frommemory()/fromfile() on the CNG backend.

Using sizeof(BCRYPT_ECCKEY_BLOB) lines the allocation up with the header the copies actually write from and with the length passed to BCryptImportKeyPair(). Keeping it in step with the public-key path means the private blob is described to CNG with exactly the bytes it holds.

Follow-up to 3e72343 #1315

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.

Copilot review overview

🟢 Approval recommended

The change is focused and resolves the incorrect allocation-size calculation.

Review effort: Lite
Findings: None

What changed in this PR

Fixes WinCNG ECC private-key blob sizing to use the correct header size.

Changes:

  • Uses sizeof(BCRYPT_ECCKEY_BLOB) for private-key allocation.
File Description
src/​wincng.c Corrects ECC private-key blob allocation sizing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vszakats vszakats closed this in 01d0c89 Oct 2, 2026
@vszakats

vszakats commented Oct 2, 2026

Copy link
Copy Markdown
Member

Thanks!

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.

3 participants