Repository navigation
Conversation
This reverts commit 326139d.
There was a problem hiding this comment.
🟡 Changes recommended
Fixed-group key exchanges always fail, and two backends mishandle allocation failure.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates bignum binary conversion to initialize destinations consistently across crypto backends.
Changes:
- Changes
ssh2_bn_from_bin()to acceptssh2_bn **. - Removes call sites’ explicit initialization.
- Adds backend-specific conversion implementations.
File summaries
| File | Description |
|---|---|
src/wincng.c |
Updates Windows CNG conversion. |
src/os400qc3.c |
Migrates IBM i bignum callers. |
src/openssl.h |
Removes conversion macro. |
src/openssl.c |
Adds OpenSSL conversion function. |
src/mbedtls.h |
Removes conversion macro. |
src/mbedtls.c |
Adds mbedTLS conversion function. |
src/libgcrypt.h |
Updates conversion macro indirection. |
src/kex.c |
Migrates key-exchange bignum initialization. |
src/crypto.h |
Updates the shared conversion API. |
Review details
Suppressed comments (3)
src/kex.c:868
- Because
key_state->pnow starts asNULL, this condition never callsssh2_bn_from_bin()and group14 key exchange always fails. The conversion call itself should perform allocation and report any failure.
else if(!key_state->p ||
ssh2_bn_from_bin(&key_state->p, p_value, 256)) {
src/kex.c:978
- The preceding
key_state->p = NULLmakes this condition unconditionally true beforessh2_bn_from_bin()can run, so group16 key exchange always fails. Test the conversion result without the pre-allocation null check.
if(!key_state->p || ssh2_bn_from_bin(&key_state->p, p_value, 512)) {
src/kex.c:1111
key_state->pis initialized toNULL, so this||short-circuits and group18 key exchange always takes the error path. Callssh2_bn_from_bin()directly so it can initializep.
else if(!key_state->p ||
ssh2_bn_from_bin(&key_state->p, p_value, 1024)) {
- Files reviewed: 9/9 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
OS/400 wrappers can falsely report success and leak allocations when passed NULL output bignums.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
src/os400qc3.c:1322
pubis passed by value, so taking&puballowsssh2_bn_from_bin()to allocate only into the local copy. If the caller's public-bignum allocation failed (for example atkex.c:429), this now returns success, leaks the new bignum, and leaves the caller's output NULL. Preserve the output contract by rejecting NULL before conversion (or change the interface to propagate allocation).
return ssh2_bn_from_bin(&pub, (unsigned char *)pubkey, pubkeylen);
src/os400qc3.c:1372
- Taking the address of this by-value
secretparameter means the converter can allocate a bignum that is never propagated to the caller. On a NULL destination this returns success and leaks memory, while the caller still has NULL; reject NULL before conversion or make the output parameter indirect throughout the interface.
return ssh2_bn_from_bin(&secret, (unsigned char *)secretbuf, secretbuflen);
- Files reviewed: 10/10 changed files
- Comments generated: 3
- Review effort level: Balanced
`bn` is a by-value parameter here. If it is NULL, the new converter allocates through the address of this local copy, returns success, and leaks the allocation without updating the caller; previously this path returned an error. Reject a NULL destination before calling the allocating API. This issue also appears in the following locations of the same file: - line 1322 - line 1372 libssh2#2594 (comment)
There was a problem hiding this comment.
🟡 Changes recommended
The documented allocation condition contradicts the implemented pointer-to-pointer contract.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 1
- Review effort level: Balanced
To better hide backend-specific differences and t bring the init
sub-steps (1. allocation, 2. conversion) close to each other.
Also:
ssh2_bn_from_bin()andssh2_bn_set_word().Ref: #2583 (comment)