1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Check for null pointers in dh_cleanup.

If we have to abandon a Diffie-Hellman key exchange part way through
(e.g. the connection slams shut), and we haven't yet run all the
stages of the DH algorithm, then some of the mp_ints in the dh_ctx
will be NULL. So we shouldn't mp_free them without checking first.
This commit is contained in:
Simon Tatham 2019-01-02 08:55:03 +00:00
parent 606cf4c22b
commit 24b9e6716d

15
sshdh.c
View File

@ -186,11 +186,16 @@ int dh_modulus_bit_size(const struct dh_ctx *ctx)
*/
void dh_cleanup(struct dh_ctx *ctx)
{
mp_free(ctx->x);
mp_free(ctx->e);
mp_free(ctx->p);
mp_free(ctx->g);
mp_free(ctx->q);
if (ctx->x)
mp_free(ctx->x);
if (ctx->e)
mp_free(ctx->e);
if (ctx->p)
mp_free(ctx->p);
if (ctx->g)
mp_free(ctx->g);
if (ctx->q)
mp_free(ctx->q);
sfree(ctx);
}