Skip to content

openssl: fix allocator/free mismatch in ossl_ecdsa_evp_to_pubkey() with OpenSSL 3+ - #2543

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:ossl-alloc-free-mismatch
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:ossl-alloc-free-mismatch

Conversation

@vszakats

@vszakats vszakats commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

OpenSSL 3+ was allocating with SSH2_ALLOC() and freeing with free(),
OpenSSL 1.1.1 was OK. Fix by upgrading the OpenSSL 1.1.1 codepath to use
SSH2_ALLOC() and free with SSH2_FREE().

Follow-up to b0ab005 #1207


That fixed, I think no libssh2 code should ever be using bare malloc().
Fixing that'd still leave a bunch of backend-API-specific allocators, e.g.
OPENSSL_malloc(), mbedtls_calloc(), maybe more, which were often
mismatched with their free counterpart, maybe some of them still are.
I don't think these should be used unless the API requires it.

OpenSSL 3 was allocating with `SSH2_ALLOC()` and freeing with free(),
OpenSSL 1.1.1 was OK. Fix by upgrading the OpenSSL 1.1.1 codepath to use
`SSH2_ALLOC()` and free with `SSH2_FREE()`.

Follow-up to b0ab005 libssh2#1207
@vszakats vszakats changed the title openssl: fix alloc/free mismatch in ossl_ecdsa_evp_to_pubkey() openssl: fix alloc/free mismatch in ossl_ecdsa_evp_to_pubkey() with OpenSSL 3 Aug 27, 2026
@vszakats vszakats added the bug label Aug 27, 2026
@vszakats
vszakats requested a balanced review from Copilot August 27, 2026 10:28

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 allocator mismatch introduced by OpenSSL 3 support.

Changes:

  • Allocates the EC public-key buffer with SSH2_ALLOC().
  • Releases it consistently with SSH2_FREE().

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

@vszakats vszakats changed the title openssl: fix alloc/free mismatch in ossl_ecdsa_evp_to_pubkey() with OpenSSL 3 openssl: fix alloc/free mismatch in ossl_ecdsa_evp_to_pubkey() with OpenSSL 3+ Aug 27, 2026
@vszakats vszakats changed the title openssl: fix alloc/free mismatch in ossl_ecdsa_evp_to_pubkey() with OpenSSL 3+ openssl: fix allocator/free mismatch in ossl_ecdsa_evp_to_pubkey() with OpenSSL 3+ Aug 27, 2026
@vszakats vszakats closed this in 2192c2e Aug 27, 2026
@vszakats
vszakats deleted the ossl-alloc-free-mismatch branch August 27, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants