Repository navigation
Conversation
session to key alloc/free functions, switch to SSH2 allocatorssession to key alloc/free functions, switch to SSH2 allocator
450bebe to
eacaca1
Compare
There was a problem hiding this comment.
Pull request overview
Propagates sessions through crypto key lifecycle APIs to support libssh2’s custom allocators.
Changes:
- Adds session parameters to key constructors and destructors.
- Migrates selected mbedTLS, Windows CNG, and OS/400 allocations.
- Updates callers, backend macros, and documentation.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/wincng.c |
Migrates key-context allocation and cleanup. |
src/os400qc3.h |
Updates RSA cleanup macro. |
src/os400qc3.c |
Migrates crypto-context allocation. |
src/openssl.h |
Updates destructor macros. |
src/openssl.c |
Propagates session arguments. |
src/mbedtls.c |
Uses session allocators for key contexts. |
src/libgcrypt.h |
Updates destructor macros. |
src/libgcrypt.c |
Propagates session arguments. |
src/kex.c |
Passes sessions during ECDSA cleanup. |
src/hostkey.c |
Updates host-key construction and destruction. |
src/HACKING-CRYPTO.md |
Documents revised crypto interfaces. |
src/crypto.h |
Updates shared crypto declarations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| { | ||
| if(!ctx) | ||
| ctx = malloc(sizeof(*ctx)); | ||
| ctx = SSH2_ALLOC(session, sizeof(*ctx)); |
There was a problem hiding this comment.
Backtracking from this, destructors/allocators tangled up, plus recursive stuff.
Maybe doable if all the low-level functions got a session arg (seems overkill),
or needs untangling these.
eacaca1 to
c93079d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
src/wincng.c:1394
pbKeyObjectis not always owned by the session allocator. The RSA private-key parser storespbStructInfohere afterwcng_asn_decode()allocated it withmalloc()(lines 938 and 1266), so this new session deallocator call passes a foreign pointer whenever a custom allocator is configured. Allocate/rehome that decoded blob through the session allocator, or track its allocator and release it consistently.
ssh2_zero_free(session, rsa->pbKeyObject, rsa->cbKeyObject);
Dang, another tangle-up. |
6cd768b to
33de14b
Compare
This reverts commit 43605e12b34ef0b5944422ea1b0b785389d954b2.
This reverts commit eacaca1.
33de14b to
f3cf153
Compare
…()`, `ssh2_dsa_new()` Follow-up to 5ef9591 libssh2#2559 Follow-up to d5149ca libssh2#2548 Follow-up to b0ab005 libssh2#1207
To shift allocation from raw or backend-specific allocators to libssh2's
own. To respect custom allocators set via
libssh2_session_init_ex(),and to reduce the chance for mismatched alloc/free calls.
sessiontossh2_rsa_new()andssh2_dsa_new()and all thessh2_*_free()deallocators.wcng_asn_decode()to sycn up withthe above change and avoid using mixed allocators in key contexts.
wcng_asn_decode_bns(),wcng_publickey_from_point(),wcng_privatekey_from_point().