summaryrefslogtreecommitdiffstats
path: root/crypto/bn/bn_mont.c
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2018-03-29 11:27:29 +0200
committerBernd Edlinger <bernd.edlinger@hotmail.de>2018-03-31 16:31:37 +0200
commitf91e026e38321d0c154f535ecd5af09e424e7f1b (patch)
treeed584cd2e045eb272f1ffba120c22eaab993dc52 /crypto/bn/bn_mont.c
parent803cc8c7d4fce5ba8a4b843e0d778983d5b75c9e (diff)
Fix a possible crash in BN_from_montgomery_word
Thanks to Darovskikh Andrei for for reporting this issue. Fixes: #5785 Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/5793)
Diffstat (limited to 'crypto/bn/bn_mont.c')
-rw-r--r--crypto/bn/bn_mont.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c
index c882891d5e..362390a353 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);