Don't allow BIGNUMs to become so large that computations with dmax
authorBodo Möller <bodo@openssl.org>
Sun, 3 Dec 2000 09:39:04 +0000 (09:39 +0000)
committerBodo Möller <bodo@openssl.org>
Sun, 3 Dec 2000 09:39:04 +0000 (09:39 +0000)
might overflow.

crypto/bn/bn.h
crypto/bn/bn_err.c
crypto/bn/bn_lib.c

index 3d5c91adb94b9127d3644c4063a1a5f545eb4913..a5b6ed9d4c70c5450f8899625a4bcb5c89ed7e94 100644 (file)
@@ -541,6 +541,7 @@ int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);
 #define BN_R_NOT_INITIALIZED                            107
 #define BN_R_NO_INVERSE                                         108
 #define BN_R_P_IS_NOT_PRIME                             112
+#define BN_R_TOO_LARGE                                  114
 #define BN_R_TOO_MANY_ITERATIONS                        113
 #define BN_R_TOO_MANY_TEMPORARY_VARIABLES               109
 
index afb9320322606be0939f0af02c2fc9d30932a7d2..2bb311f95cb9ac81379600adba52a4c7ec707c8b 100644 (file)
@@ -105,6 +105,7 @@ static ERR_STRING_DATA BN_str_reasons[]=
 {BN_R_NOT_INITIALIZED                    ,"not initialized"},
 {BN_R_NO_INVERSE                         ,"no inverse"},
 {BN_R_P_IS_NOT_PRIME                     ,"p is not prime"},
+{BN_R_TOO_LARGE                          ,"too large"},
 {BN_R_TOO_MANY_ITERATIONS                ,"too many iterations"},
 {BN_R_TOO_MANY_TEMPORARY_VARIABLES       ,"too many temporary variables"},
 {0,NULL}
index 050e02bd3a9c97dfedebbc863b3d9246959cc076..096bcf183583d6c3d189abb65395bd3b6b266437 100644 (file)
@@ -312,6 +312,12 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        const BN_ULONG *B;
        int i;
 
+       if (words > (INT_MAX/(4*BN_BITS2)))
+               {
+               BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_TOO_LARGE);
+               return NULL;
+               }
+
        bn_check_top(b);        
        if (BN_get_flags(b,BN_FLG_STATIC_DATA))
                {