test/ecdsatest.c:229: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_dec2bn`.
Showing all 15 steps of the trace


test/ecdsatest.c:209:16: Call
207.       BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid));
208.       /* create the key */
209.       if ((key = EC_KEY_new_by_curve_name(nid)) == NULL)
                      ^
210.           goto x962_int_err;
211.       use_fake = 1;

crypto/ec/ec_key.c:82:18: Call
  80.       if (ret == NULL)
  81.           return NULL;
  82.       ret->group = EC_GROUP_new_by_curve_name(nid);
                         ^
  83.       if (ret->group == NULL) {
  84.           EC_KEY_free(ret);

crypto/ec/ec_curve.c:3139:19: Call
    3137.       for (i = 0; i < curve_list_length; i++)
    3138.           if (curve_list[i].nid == nid) {
    3139.               ret = ec_group_new_from_data(curve_list[i]);
                              ^
    3140.               break;
    3141.           }

crypto/ec/ec_curve.c:3102:10: Call
      3100.           goto err;
      3101.       }
      3102.       if (!EC_GROUP_set_generator(group, P, order, x)) {
                       ^
      3103.           ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);
      3104.           goto err;

crypto/ec/ec_lib.c:265:1: Parameter `group->cofactor->d`
        263.   }
        264.   
        265. > int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
        266.                              const BIGNUM *order, const BIGNUM *cofactor)
        267.   {

test/ecdsatest.c:229:10: Call
227.       if ((r = BN_new()) == NULL || (s = BN_new()) == NULL)
228.           goto x962_int_err;
229.       if (!BN_dec2bn(&r, r_in) || !BN_dec2bn(&s, s_in))
                ^
230.           goto x962_int_err;
231.       ECDSA_SIG_get0(&sig_r, &sig_s, signature);

crypto/bn/bn_print.c:244:1: Parameter `*(*bn)->d`
  242.   }
  243.   
  244. > int BN_dec2bn(BIGNUM **bn, const char *a)
  245.   {
  246.       BIGNUM *ret = NULL;

crypto/bn/bn_print.c:277:9: Call
  275.   
  276.       /* i is the number of digests, a bit of an over expand; */
  277.       if (bn_expand(ret, i * 4) == NULL)
                 ^
  278.           goto err;
  279.   

crypto/bn/bn_lib.c:390:1: Parameter `*b->d`
    388.    */
    389.   
    390. > BIGNUM *bn_expand2(BIGNUM *b, int words)
    391.   {
    392.       bn_check_top(b);

crypto/bn/bn_print.c:290:13: Call
  288.           if (++j == BN_DEC_NUM) {
  289.               BN_mul_word(ret, BN_DEC_CONV);
  290.               BN_add_word(ret, l);
                     ^
  291.               l = 0;
  292.               j = 0;

crypto/bn/bn_word.c:123:1: Parameter `*a->d`
    121.   }
    122.   
    123. > int BN_add_word(BIGNUM *a, BN_ULONG w)
    124.   {
    125.       BN_ULONG l;

crypto/bn/bn_word.c:140:13: Call
    138.       if (a->neg) {
    139.           a->neg = 0;
    140.           i = BN_sub_word(a, w);
                       ^
    141.           if (!BN_is_zero(a))
    142.               a->neg = !(a->neg);

crypto/bn/bn_word.c:159:1: <Length trace>
157.   }
158.   
159. > int BN_sub_word(BIGNUM *a, BN_ULONG w)
160.   {
161.       int i;

crypto/bn/bn_word.c:159:1: Parameter `*a->d`
      157.   }
      158.   
      159. > int BN_sub_word(BIGNUM *a, BN_ULONG w)
      160.   {
      161.       int i;

crypto/bn/bn_word.c:184:27: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_dec2bn` 
      182.       }
      183.   
      184.       if ((a->top == 1) && (a->d[0] < w)) {
                                       ^
      185.           a->d[0] = w - a->d[0];
      186.           a->neg = 1;

int BN_sub_word(BIGNUM *a, BN_ULONG w)
{
    int i;
    bn_check_top(a);
    w &= BN_MASK2;
    if (!w)
        return 1;
    if (BN_is_zero(a)) {
        i = BN_set_word(a, w);
        if (i != 0)
            BN_set_negative(a, 1);
        return i;
    }
    if (a->neg) {
        a->neg = 0;
        i = BN_add_word(a, w);
        a->neg = 1;
        return (i);
    }
    if ((a->top == 1) && (a->d[0] < w)) {
        a->d[0] = w - a->d[0];
        a->neg = 1;
        return (1);
    }
    i = 0;
    for (;;) {
        if (a->d[i] >= w) {
            a->d[i] -= w;
            break;
        } else {
            a->d[i] = (a->d[i] - w) & BN_MASK2;
            i++;
            w = 1;
        }
    }
    if ((a->d[i] == 0) && (i == (a->top - 1)))
        a->top--;
    bn_check_top(a);
    return (1);
}
['int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in)\n{\n    int ret = 0;\n    const char message[] = "abc";\n    unsigned char digest[20];\n    unsigned int dgst_len = 0;\n    EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n    EC_KEY *key = NULL;\n    ECDSA_SIG *signature = NULL;\n    BIGNUM *r = NULL, *s = NULL;\n    BIGNUM *kinv = NULL, *rp = NULL;\n    BIGNUM *sig_r, *sig_s;\n    if (md_ctx == NULL)\n        goto x962_int_err;\n    if (!EVP_DigestInit(md_ctx, EVP_sha1())\n        || !EVP_DigestUpdate(md_ctx, (const void *)message, 3)\n        || !EVP_DigestFinal(md_ctx, digest, &dgst_len))\n        goto x962_int_err;\n    BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid));\n    if ((key = EC_KEY_new_by_curve_name(nid)) == NULL)\n        goto x962_int_err;\n    use_fake = 1;\n    if (!EC_KEY_generate_key(key))\n        goto x962_int_err;\n    BIO_printf(out, ".");\n    (void)BIO_flush(out);\n    use_fake = 1;\n    if (!ECDSA_sign_setup(key, NULL, &kinv, &rp))\n        goto x962_int_err;\n    signature = ECDSA_do_sign_ex(digest, 20, kinv, rp, key);\n    if (signature == NULL)\n        goto x962_int_err;\n    BIO_printf(out, ".");\n    (void)BIO_flush(out);\n    if ((r = BN_new()) == NULL || (s = BN_new()) == NULL)\n        goto x962_int_err;\n    if (!BN_dec2bn(&r, r_in) || !BN_dec2bn(&s, s_in))\n        goto x962_int_err;\n    ECDSA_SIG_get0(&sig_r, &sig_s, signature);\n    if (BN_cmp(sig_r, r) || BN_cmp(sig_s, s))\n        goto x962_int_err;\n    BIO_printf(out, ".");\n    (void)BIO_flush(out);\n    if (ECDSA_do_verify(digest, 20, signature, key) != 1)\n        goto x962_int_err;\n    BIO_printf(out, ".");\n    (void)BIO_flush(out);\n    BIO_printf(out, " ok\\n");\n    ret = 1;\n x962_int_err:\n    if (!ret)\n        BIO_printf(out, " failed\\n");\n    EC_KEY_free(key);\n    ECDSA_SIG_free(signature);\n    BN_free(r);\n    BN_free(s);\n    EVP_MD_CTX_free(md_ctx);\n    BN_clear_free(kinv);\n    BN_clear_free(rp);\n    return ret;\n}', 'EC_KEY *EC_KEY_new_by_curve_name(int nid)\n{\n    EC_KEY *ret = EC_KEY_new();\n    if (ret == NULL)\n        return NULL;\n    ret->group = EC_GROUP_new_by_curve_name(nid);\n    if (ret->group == NULL) {\n        EC_KEY_free(ret);\n        return NULL;\n    }\n    if (ret->meth->set_group != NULL\n        && ret->meth->set_group(ret, ret->group) == 0) {\n        EC_KEY_free(ret);\n        return NULL;\n    }\n    return ret;\n}', 'EC_GROUP *EC_GROUP_new_by_curve_name(int nid)\n{\n    size_t i;\n    EC_GROUP *ret = NULL;\n    if (nid <= 0)\n        return NULL;\n    for (i = 0; i < curve_list_length; i++)\n        if (curve_list[i].nid == nid) {\n            ret = ec_group_new_from_data(curve_list[i]);\n            break;\n        }\n    if (ret == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_BY_CURVE_NAME, EC_R_UNKNOWN_GROUP);\n        return NULL;\n    }\n    EC_GROUP_set_curve_name(ret, nid);\n    return ret;\n}', 'static EC_GROUP *ec_group_new_from_data(const ec_list_element curve)\n{\n    EC_GROUP *group = NULL;\n    EC_POINT *P = NULL;\n    BN_CTX *ctx = NULL;\n    BIGNUM *p = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL, *order =\n        NULL;\n    int ok = 0;\n    int seed_len, param_len;\n    const EC_METHOD *meth;\n    const EC_CURVE_DATA *data;\n    const unsigned char *params;\n    if ((ctx = BN_CTX_new()) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    data = curve.data;\n    seed_len = data->seed_len;\n    param_len = data->param_len;\n    params = (const unsigned char *)(data + 1);\n    params += seed_len;\n    if ((p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) == NULL\n        || (a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) == NULL\n        || (b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (curve.meth != 0) {\n        meth = curve.meth();\n        if (((group = EC_GROUP_new(meth)) == NULL) ||\n            (!(group->meth->group_set_curve(group, p, a, b, ctx)))) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    } else if (data->field_type == NID_X9_62_prime_field) {\n        if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    }\n#ifndef OPENSSL_NO_EC2M\n    else {\n        if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    }\n#endif\n    if ((P = EC_POINT_new(group)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) == NULL\n        || (y = BN_bin2bn(params + 4 * param_len, param_len, NULL)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) == NULL\n        || !BN_set_word(x, (BN_ULONG)data->cofactor)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (!EC_GROUP_set_generator(group, P, order, x)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (seed_len) {\n        if (!EC_GROUP_set_seed(group, params - seed_len, seed_len)) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    }\n    ok = 1;\n err:\n    if (!ok) {\n        EC_GROUP_free(group);\n        group = NULL;\n    }\n    EC_POINT_free(P);\n    BN_CTX_free(ctx);\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    BN_free(order);\n    BN_free(x);\n    BN_free(y);\n    return group;\n}', 'int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,\n                           const BIGNUM *order, const BIGNUM *cofactor)\n{\n    if (generator == NULL) {\n        ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);\n        return 0;\n    }\n    if (group->generator == NULL) {\n        group->generator = EC_POINT_new(group);\n        if (group->generator == NULL)\n            return 0;\n    }\n    if (!EC_POINT_copy(group->generator, generator))\n        return 0;\n    if (order != NULL) {\n        if (!BN_copy(group->order, order))\n            return 0;\n    } else\n        BN_zero(group->order);\n    if (cofactor != NULL) {\n        if (!BN_copy(group->cofactor, cofactor))\n            return 0;\n    } else\n        BN_zero(group->cofactor);\n    ec_precompute_mont_data(group);\n    return 1;\n}', "int BN_dec2bn(BIGNUM **bn, const char *a)\n{\n    BIGNUM *ret = NULL;\n    BN_ULONG l = 0;\n    int neg = 0, i, j;\n    int num;\n    if ((a == NULL) || (*a == '\\0'))\n        return (0);\n    if (*a == '-') {\n        neg = 1;\n        a++;\n    }\n    for (i = 0; isdigit((unsigned char)a[i]); i++) ;\n    num = i + neg;\n    if (bn == NULL)\n        return (num);\n    if (*bn == NULL) {\n        if ((ret = BN_new()) == NULL)\n            return (0);\n    } else {\n        ret = *bn;\n        BN_zero(ret);\n    }\n    if (bn_expand(ret, i * 4) == NULL)\n        goto err;\n    j = BN_DEC_NUM - (i % BN_DEC_NUM);\n    if (j == BN_DEC_NUM)\n        j = 0;\n    l = 0;\n    while (*a) {\n        l *= 10;\n        l += *a - '0';\n        a++;\n        if (++j == BN_DEC_NUM) {\n            BN_mul_word(ret, BN_DEC_CONV);\n            BN_add_word(ret, l);\n            l = 0;\n            j = 0;\n        }\n    }\n    ret->neg = neg;\n    bn_correct_top(ret);\n    *bn = ret;\n    bn_check_top(ret);\n    return (num);\n err:\n    if (*bn == NULL)\n        BN_free(ret);\n    return (0);\n}", 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n{\n    BN_ULONG l;\n    int i;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return 1;\n    if (BN_is_zero(a))\n        return BN_set_word(a, w);\n    if (a->neg) {\n        a->neg = 0;\n        i = BN_sub_word(a, w);\n        if (!BN_is_zero(a))\n            a->neg = !(a->neg);\n        return (i);\n    }\n    for (i = 0; w != 0 && i < a->top; i++) {\n        a->d[i] = l = (a->d[i] + w) & BN_MASK2;\n        w = (w > l) ? 1 : 0;\n    }\n    if (w && i == a->top) {\n        if (bn_wexpand(a, a->top + 1) == NULL)\n            return 0;\n        a->top++;\n        a->d[i] = w;\n    }\n    bn_check_top(a);\n    return (1);\n}', 'int BN_sub_word(BIGNUM *a, BN_ULONG w)\n{\n    int i;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return 1;\n    if (BN_is_zero(a)) {\n        i = BN_set_word(a, w);\n        if (i != 0)\n            BN_set_negative(a, 1);\n        return i;\n    }\n    if (a->neg) {\n        a->neg = 0;\n        i = BN_add_word(a, w);\n        a->neg = 1;\n        return (i);\n    }\n    if ((a->top == 1) && (a->d[0] < w)) {\n        a->d[0] = w - a->d[0];\n        a->neg = 1;\n        return (1);\n    }\n    i = 0;\n    for (;;) {\n        if (a->d[i] >= w) {\n            a->d[i] -= w;\n            break;\n        } else {\n            a->d[i] = (a->d[i] - w) & BN_MASK2;\n            i++;\n            w = 1;\n        }\n    }\n    if ((a->d[i] == 0) && (i == (a->top - 1)))\n        a->top--;\n    bn_check_top(a);\n    return (1);\n}']