Skip to content

Commit

Permalink
Fix overflow in bnrand()
Browse files Browse the repository at this point in the history
Fixes #23704

Change-Id: I0352fdf7cbca6c9db5f2d662e0a29ac318111382
Jira: SECLIB-799
  • Loading branch information
tom-cosgrove-arm committed Feb 29, 2024
1 parent 2d70cc9 commit 4eefbee
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crypto/bn/bn_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom,
if (bits < 0 || (bits == 1 && top > 0))
goto toosmall;

bytes = (bits + 7) / 8;
bit = (bits - 1) % 8;
bytes = bits / 8 + (14 - bit) / 8; /* Same as (bits + 7) / 8 but can't overflow */
mask = 0xff << (bit + 1);

buf = OPENSSL_malloc(bytes);
Expand Down

0 comments on commit 4eefbee

Please sign in to comment.