Skip to content

openssl: fix NULL derefs on OOM in ossl_e*_sk_openssh_priv_to_pubkey() - #2292

Closed
vszakats wants to merge 5 commits into
libssh2:masterfrom
vszakats:openssl-null-deref
Closed

vszakats wants to merge 5 commits into
libssh2:masterfrom
vszakats:openssl-null-deref

Conversation

@vszakats

@vszakats vszakats commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

"If SSH2_ALLOC returns NULL, ssh2_explicit_zero and memcpy will
dereference a NULL pointer. The return value of SSH2_ALLOC should be
checked before use. The same issue exists in
ossl_ecdsa_sk_openssh_priv_to_pubkey at lines 3132-3134."

Also: drop a redundant NULL check.

Reported by GitHub Code Quality and Copilot

Follow-up to ed439a2 #698

"If `SSH2_ALLOC` returns NULL, `ssh2_explicit_zero` and `memcpy` will
dereference a NULL pointer. The return value of `SSH2_ALLOC` should be
checked before use. The same issue exists in
`ossl_ecdsa_sk_openssh_priv_to_pubkey` at lines 3132–3134."

Follow-up to ed439a2 libssh2#698

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 a potential NULL pointer dereference in the OpenSSL backend when deriving an [email protected] public key from an OpenSSH private key, by validating the result of SSH2_ALLOC before calling ssh2_explicit_zero/memcpy.

Changes:

  • Add an OOM/NULL check after allocating the ED25519 application buffer and error out via clean_exit if allocation fails.

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

Comment thread src/openssl.c Resolved
@vszakats vszakats changed the title openssl: fix NULL deref on OOM in ossl_ed25519_sk_openssh_priv_to_pubkey() openssl: fix NULL deref on OOM in ossl_e*_sk_openssh_priv_to_pubkey() Jul 14, 2026
@vszakats vszakats changed the title openssl: fix NULL deref on OOM in ossl_e*_sk_openssh_priv_to_pubkey() openssl: fix NULL derefs on OOM in ossl_e*_sk_openssh_priv_to_pubkey() Jul 14, 2026

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/openssl.c Resolved

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/openssl.c Resolved
@vszakats vszakats closed this in 7e2d775 Jul 14, 2026
@vszakats
vszakats deleted the openssl-null-deref branch July 14, 2026 01:25
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