Skip to content

Commit

Permalink
Fix memory leak in DH_get_nid()
Browse files Browse the repository at this point in the history
If q is non-NULL but p is indeed a safe prime, a modified copy
of p could be leaked.

Reviewed-by: Rich Salz <[email protected]>
(Merged from openssl#4525)
  • Loading branch information
kaduk committed Oct 12, 2017
1 parent 141e470 commit 8abeefe
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions crypto/dh/dh_rfc7919.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ int DH_get_nid(const DH *dh)
BIGNUM *q = BN_dup(dh->p);

/* Check q = p * 2 + 1 we already know q is odd, so just shift right */
if (q == NULL || !BN_rshift1(q, q) || !BN_cmp(dh->q, q)) {
BN_free(q);
return NID_undef;
}
if (q == NULL || !BN_rshift1(q, q) || !BN_cmp(dh->q, q))
nid = NID_undef;
BN_free(q);
}
return nid;
}

0 comments on commit 8abeefe

Please sign in to comment.