From 30befffe04314dfd8e6168485ae1a82dff331472 Mon Sep 17 00:00:00 2001 From: Josh Brobst Date: Sun, 11 May 2025 14:15:58 -0400 Subject: [PATCH] kex: fix DH-GEX-sha256 bignum initialization In `kex_method_diffie_hellman_group_exchange_sha256_key_exchange`, `p` and `g` are later initialized with `_libssh2_bn_from_bin`, so they should be initially created using `_libssh2_bn_init_from_bin` rather than `_libssh2_bn_init`, as is done in `kex_method_diffie_hellman_group_exchange_sha1_key_exchange`. Fixing memory leaks when using the libgcrypt backend. Follow-up to 09c5e59933daf67b833f34b8c388766abc038483 Ref: https://web.archive.org/web/trac.libssh2.org/ticket/168 Closes #1599 --- src/kex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kex.c b/src/kex.c index ea9307d0..1a8f70b8 100644 --- a/src/kex.c +++ b/src/kex.c @@ -1590,8 +1590,8 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange( int rc; if(key_state->state == libssh2_NB_state_idle) { - key_state->p = _libssh2_bn_init(); - key_state->g = _libssh2_bn_init(); + key_state->p = _libssh2_bn_init_from_bin(); + key_state->g = _libssh2_bn_init_from_bin(); /* Ask for a P and G pair */ key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST; _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_MINGROUP);