Repository navigation
Conversation
Prior to this patch it was loading a PEM-formatted private key via OpenSSL. When successful, it did nothing, when failed, it fell back trying to load an OpenSSH-formatted key. This was no-op in itself, but SK keys don't support the PEM format AFAIU, so the function went to the OpenSSH codepath when used as intended. In both cases, it leaked the OpenSSL memory object. Drop the superfluous intermediate step and map this function directly to the internal worker `ossl_key_sk_from_openssh_blob()`, also fixing the memory leak and unnecessary processing. Follow-up to ed439a2 libssh2#698
|
Still having a hard time understanding how is this supposed to work edit: even more, it's two in-memory functions, both handling sk keys. edit 2: maybe that should have been two tries with the two method |
There was a problem hiding this comment.
Pull request overview
This PR simplifies the OpenSSL backend’s ssh2_sk_pub_keyfilememory() implementation by removing a no-op PEM private-key parse attempt and mapping the function directly to the OpenSSH SK key parsing flow, addressing unnecessary work and the reported OpenSSL object leak in the prior logic.
Changes:
- Removes the intermediate
PEM_read_bio_PrivateKey()step fromssh2_sk_pub_keyfilememory()and routes directly through OpenSSH-format parsing. - Adjusts the
passphrasehandling to align with the OpenSSH PEM parser’s expected type. - Drops the now-unneeded internal SK worker wrapper and related plumbing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prior to this patch it was loading a PEM-formatted private key via
OpenSSL. When successful, it did nothing, when failed, it fell back
trying to load an OpenSSH-formatted key. This was no-op in itself, but
SK keys don't support the PEM format AFAIU, so the function went to the
OpenSSH codepath when used as intended. In both cases, it leaked the
OpenSSL memory object.
Drop the superfluous intermediate step and map this function directly to
the internal worker
ossl_key_sk_from_openssh_blob(), also fixing thememory leak and unnecessary processing.
Also:
passphrasetype with rest of internal APIs.Memleak reported repeatedly by GitHub Code Quality
Follow-up to ed439a2 #698
"
stis initialized to -1 at line 4242, and is only assigned in theif(!pk)branch. IfPEM_read_bio_PrivateKeysucceeds (i.e.,pkisnon-NULL),
stis never updated and the function always returns -1. Thenon-NULL
pkcase should be handled, including freeingpkbeforereturning."
"When
PEM_read_bio_PrivateKeysucceeds (pk != NULL),stremains -1and the function immediately returns it without processing the key or
freeing
pk. This causes a memory leak of theEVP_PKEYobject andalways returns failure for PEM-format SK keys. The function needs to
handle the successful PEM parse case, and
EVP_PKEY_free(pk)must becalled before returning."