1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-27 00:18:12 +03:00

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 09c5e59933
Ref: https://web.archive.org/web/trac.libssh2.org/ticket/168

Closes #1599
This commit is contained in:
Josh Brobst
2025-05-11 14:15:58 -04:00
committed by Viktor Szakats
parent cea8783ed8
commit 30befffe04

View File

@@ -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);