Skip to content

Commit 42437d1

Browse files
rheniumandi34
authored andcommitted
Fix overflow check in BN_bn2dec()
Fix an off by one error in the overflow check added by 07bed46f332fc ("Check for errors in BN_bn2dec()"). Change-Id: I1f193d3ba326e4e36335e708582d0bf1a004d023 Reviewed-by: Stephen Henson <steve@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org>
1 parent 89b686c commit 42437d1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

crypto/bn/bn_print.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,14 @@ char *BN_bn2dec(const BIGNUM *a)
139139
if (BN_is_negative(t))
140140
*p++ = '-';
141141

142-
i=0;
143142
while (!BN_is_zero(t))
144143
{
144+
if (lp - bn_data >= bn_data_num)
145+
goto err;
145146
*lp=BN_div_word(t,BN_DEC_CONV);
146147
if (*lp == (BN_ULONG)-1)
147148
goto err;
148149
lp++;
149-
if (lp - bn_data >= bn_data_num)
150-
goto err;
151150
}
152151
lp--;
153152
/* We now have a series of blocks, BN_DEC_NUM chars

0 commit comments

Comments
 (0)