From: Bernd Edlinger Date: Thu, 29 Mar 2018 09:27:29 +0000 (+0200) Subject: Fix a possible crash in BN_from_montgomery_word X-Git-Tag: OpenSSL_1_1_0i~109 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2392eb77d237684a32b1290fc9e3d0e2f3b08554;p=oweals%2Fopenssl.git Fix a possible crash in BN_from_montgomery_word Thanks to Darovskikh Andrei for for reporting this issue. Fixes: #5785 Fixes: #6302 Cherry-picked from f91e026e3832 (without test/bntest.c) Reviewed-by: Rich Salz Reviewed-by: Matthias St. Pierre (Merged from https://github.com/openssl/openssl/pull/6310) --- diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c index c0c174650c..dad3d07b3d 100644 --- a/crypto/bn/bn_mont.c +++ b/crypto/bn/bn_mont.c @@ -95,6 +95,8 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) /* clear the top words of T */ i = max - r->top; + if (i < 0) + return 0; if (i) memset(&rp[r->top], 0, sizeof(*rp) * i);