Skip to content

wincng: fix to bail out on ECDH key export fail - #2190

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:wcng2
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:wcng2

Conversation

@vszakats

@vszakats vszakats commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

"When wcng_uncompressed_point_from_publickey fails, result is set to
an error code but execution falls through into the malloc / struct
initialization block instead of jumping to cleanup. This causes
*out_private_key to be allocated and populated even in the error path.
At cleanup, the key handle is destroyed via BCryptDestroyKey and
*out_private_key is freed, but the pointer is not set to NULL, leaving
the caller with a dangling pointer. A goto cleanup should follow the
ssh2_err call."

Reported by GitHub Code Quality

Follow-up to 3e72343 #1315

"When `wcng_uncompressed_point_from_publickey` fails, `result` is set to
an error code but execution falls through into the `malloc` / struct
initialization block instead of jumping to `cleanup`. This causes
`*out_private_key` to be allocated and populated even in the error path.
At `cleanup`, the key handle is destroyed via `BCryptDestroyKey` and
`*out_private_key` is freed, but the pointer is not set to NULL, leaving
the caller with a dangling pointer. A `goto cleanup` should follow the
`ssh2_err` call."

Reported by GitHub Code Quality

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

Fixes an error-path control-flow issue in the Windows CNG ECDH key creation routine to ensure the function bails out immediately when exporting the public key fails, preventing unintended private-key context allocation in that failure path.

Changes:

  • Add braces and a goto cleanup; after the ssh2_err(...) call when wcng_uncompressed_point_from_publickey fails in ssh2_ecdsa_create_key.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats closed this in 8b5acaa Jul 3, 2026
@vszakats
vszakats deleted the wcng2 branch July 3, 2026 10:52
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