Skip to content

Commit 7fe7cc5

Browse files
slontislevitte
authored andcommitted
Fix bn_gcd code to check return value when calling BN_one()
BN_one() uses the expand function which calls malloc which may fail. All other places that reference BN_one() check the return value. The issue is triggered by a memory allocation failure. Detected by PR openssl#18355 Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl#18697)
1 parent 9ef1f84 commit 7fe7cc5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crypto/bn/bn_gcd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ BIGNUM *bn_mod_inverse_no_branch(BIGNUM *in,
4747
if (R == NULL)
4848
goto err;
4949

50-
BN_one(X);
50+
if (!BN_one(X))
51+
goto err;
5152
BN_zero(Y);
5253
if (BN_copy(B, a) == NULL)
5354
goto err;
@@ -235,7 +236,8 @@ BIGNUM *int_bn_mod_inverse(BIGNUM *in,
235236
if (R == NULL)
236237
goto err;
237238

238-
BN_one(X);
239+
if (!BN_one(X))
240+
goto err;
239241
BN_zero(Y);
240242
if (BN_copy(B, a) == NULL)
241243
goto err;

0 commit comments

Comments
 (0)