From: Kazuki Yamaguchi Date: Sun, 21 Aug 2016 17:36:36 +0000 (+0900) Subject: Fix overflow check in BN_bn2dec() X-Git-Tag: OpenSSL_1_0_1u~13 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3612ff6fcec0e3d1f2a598135fe12177c0419582;p=oweals%2Fopenssl.git 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()"). Reviewed-by: Stephen Henson Reviewed-by: Matt Caswell (cherry picked from commit 099e2968ed3c7d256cda048995626664082b1b30) --- diff --git a/crypto/bn/bn_print.c b/crypto/bn/bn_print.c index b44403ecfd..a9ff271b9a 100644 --- a/crypto/bn/bn_print.c +++ b/crypto/bn/bn_print.c @@ -141,14 +141,13 @@ char *BN_bn2dec(const BIGNUM *a) if (BN_is_negative(t)) *p++ = '-'; - i = 0; while (!BN_is_zero(t)) { + if (lp - bn_data >= bn_data_num) + goto err; *lp = BN_div_word(t, BN_DEC_CONV); if (*lp == (BN_ULONG)-1) goto err; lp++; - if (lp - bn_data >= bn_data_num) - goto err; } lp--; /*