Check scalar->d before we use it (in BN_num_bits()). (Coverity ID 129)
authorBen Laurie <ben@openssl.org>
Sat, 27 Dec 2008 02:15:16 +0000 (02:15 +0000)
committerBen Laurie <ben@openssl.org>
Sat, 27 Dec 2008 02:15:16 +0000 (02:15 +0000)
crypto/ec/ec_mult.c

index 2ba173ef36422ad1c715fe3ebd5b0dc9b17cb03d..84488c9643ea9b3fc3bc0b55fb2ee9e15e0ec63c 100644 (file)
@@ -224,6 +224,12 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
                sign = -1;
                }
 
                sign = -1;
                }
 
+       if (scalar->d == NULL || scalar->top == 0)
+               {
+               ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
+               goto err;
+               }
+
        len = BN_num_bits(scalar);
        r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation
                                      * (*ret_len will be set to the actual length, i.e. at most
        len = BN_num_bits(scalar);
        r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation
                                      * (*ret_len will be set to the actual length, i.e. at most
@@ -233,12 +239,6 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
                ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
                goto err;
                }
                ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
                goto err;
                }
-
-       if (scalar->d == NULL || scalar->top == 0)
-               {
-               ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
-               goto err;
-               }
        window_val = scalar->d[0] & mask;
        j = 0;
        while ((window_val != 0) || (j + w + 1 < len)) /* if j+w+1 >= len, window_val will not increase */
        window_val = scalar->d[0] & mask;
        j = 0;
        while ((window_val != 0) || (j + w + 1 < len)) /* if j+w+1 >= len, window_val will not increase */