test/ectest.c:1890: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_GF2m_add`.
Showing all 17 steps of the trace


test/ectest.c:1871:14: Call
1869.       if (!(TEST_ptr(x = BN_new())
1870.             && TEST_ptr(y = BN_new())
1871.             && TEST_ptr(key = EC_KEY_new_by_curve_name(curves[id].nid))
                     ^
1872.             && TEST_ptr(group = EC_KEY_get0_group(key))
1873.             && TEST_ptr(meth = EC_GROUP_method_of(group))

crypto/ec/ec_key.c:25:19: Call
  23.   EC_KEY *EC_KEY_new_by_curve_name(int nid)
  24.   {
  25.       EC_KEY *ret = EC_KEY_new();
                          ^
  26.       if (ret == NULL)
  27.           return NULL;

crypto/ec/ec_key.c:20:12: Call
    18.   EC_KEY *EC_KEY_new(void)
    19.   {
    20.       return EC_KEY_new_method(NULL);
                     ^
    21.   }
    22.   

crypto/ec/ec_kmeth.c:123:5: Call
      121.   
      122.    err:
      123.       EC_KEY_free(ret);
                 ^
      124.       return NULL;
      125.   }

crypto/ec/ec_key.c:41:1: Parameter `r->priv_key->d`
        39.   }
        40.   
        41. > void EC_KEY_free(EC_KEY *r)
        42.   {
        43.       int i;

test/ectest.c:1890:14: Call
1888.       if (type == NID_X9_62_characteristic_two_field) {
1889.           /* test for binary curves */
1890.           if (!TEST_true(BN_GF2m_add(x, x, field)))
                     ^
1891.               goto err;
1892.       } else

crypto/bn/bn_gf2m.c:252:1: Parameter `*r->d`
  250.    * could be equal; r is the bitwise XOR of a and b.
  251.    */
  252. > int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
  253.   {
  254.       int i;

crypto/bn/bn_gf2m.c:268:9: Call
  266.       }
  267.   
  268.       if (bn_wexpand(r, at->top) == NULL)
                 ^
  269.           return 0;
  270.   

crypto/bn/bn_lib.c:962:1: Parameter `*a->d`
    960.   }
    961.   
    962. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    963.   {
    964.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:964:37: Call
    962.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    963.   {
    964.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                               ^
    965.   }
    966.   

crypto/bn/bn_lib.c:245:1: Parameter `*b->d`
      243.    */
      244.   
      245. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      246.   {
      247.       if (words > b->dmax) {

crypto/bn/bn_lib.c:248:23: Call
      246.   {
      247.       if (words > b->dmax) {
      248.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      249.           if (!a)
      250.               return NULL;

crypto/bn/bn_lib.c:209:1: <Offset trace>
207.   /* This is used by bn_expand2() */
208.   /* The caller MUST check that words > b->dmax before calling this */
209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
210.   {
211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: Parameter `b->top`
        207.   /* This is used by bn_expand2() */
        208.   /* The caller MUST check that words > b->dmax before calling this */
        209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        210.   {
        211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: <Length trace>
207.   /* This is used by bn_expand2() */
208.   /* The caller MUST check that words > b->dmax before calling this */
209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
210.   {
211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: Parameter `*b->d`
        207.   /* This is used by bn_expand2() */
        208.   /* The caller MUST check that words > b->dmax before calling this */
        209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        210.   {
        211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:232:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_GF2m_add` 
        230.       assert(b->top <= words);
        231.       if (b->top > 0)
        232.           memcpy(a, b->d, sizeof(*a) * b->top);
                       ^
        233.   
        234.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['static int check_ec_key_field_public_range_test(int id)\n{\n    int ret = 0, type = 0;\n    const EC_POINT *pub = NULL;\n    const EC_GROUP *group = NULL;\n    const EC_METHOD *meth = NULL;\n    const BIGNUM *field = NULL;\n    BIGNUM *x = NULL, *y = NULL;\n    EC_KEY *key = NULL;\n    if (!(TEST_ptr(x = BN_new())\n          && TEST_ptr(y = BN_new())\n          && TEST_ptr(key = EC_KEY_new_by_curve_name(curves[id].nid))\n          && TEST_ptr(group = EC_KEY_get0_group(key))\n          && TEST_ptr(meth = EC_GROUP_method_of(group))\n          && TEST_ptr(field = EC_GROUP_get0_field(group))\n          && TEST_int_gt(EC_KEY_generate_key(key), 0)\n          && TEST_int_gt(EC_KEY_check_key(key), 0)\n          && TEST_ptr(pub = EC_KEY_get0_public_key(key))\n          && TEST_int_gt(EC_POINT_get_affine_coordinates(group, pub, x, y,\n                                                         NULL), 0)))\n        goto err;\n    type = EC_METHOD_get_field_type(meth);\n#ifndef OPENSSL_NO_EC2M\n    if (type == NID_X9_62_characteristic_two_field) {\n        if (!TEST_true(BN_GF2m_add(x, x, field)))\n            goto err;\n    } else\n#endif\n    if (type == NID_X9_62_prime_field) {\n        if (!TEST_true(BN_add(x, x, field)))\n            goto err;\n    } else {\n        TEST_error("Unsupported EC_METHOD field_type");\n        goto err;\n    }\n    if (!TEST_int_le(EC_KEY_set_public_key_affine_coordinates(key, x, y), 0))\n        goto err;\n    ret = 1;\nerr:\n    BN_free(x);\n    BN_free(y);\n    EC_KEY_free(key);\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_KEY *EC_KEY_new(void)\n{\n    return EC_KEY_new_method(NULL);\n}', 'EC_KEY *EC_KEY_new_method(ENGINE *engine)\n{\n    EC_KEY *ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL) {\n        ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    ret->references = 1;\n    ret->lock = CRYPTO_THREAD_lock_new();\n    if (ret->lock == NULL) {\n        ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n        OPENSSL_free(ret);\n        return NULL;\n    }\n    ret->meth = EC_KEY_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n    if (engine != NULL) {\n        if (!ENGINE_init(engine)) {\n            ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);\n            goto err;\n        }\n        ret->engine = engine;\n    } else\n        ret->engine = ENGINE_get_default_EC();\n    if (ret->engine != NULL) {\n        ret->meth = ENGINE_get_EC(ret->engine);\n        if (ret->meth == NULL) {\n            ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);\n            goto err;\n        }\n    }\n#endif\n    ret->version = 1;\n    ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;\n    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) {\n        goto err;\n    }\n    if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {\n        ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_INIT_FAIL);\n        goto err;\n    }\n    return ret;\n err:\n    EC_KEY_free(ret);\n    return NULL;\n}', 'void EC_KEY_free(EC_KEY *r)\n{\n    int i;\n    if (r == NULL)\n        return;\n    CRYPTO_DOWN_REF(&r->references, &i, r->lock);\n    REF_PRINT_COUNT("EC_KEY", r);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    if (r->meth != NULL && r->meth->finish != NULL)\n        r->meth->finish(r);\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(r->engine);\n#endif\n    if (r->group && r->group->meth->keyfinish)\n        r->group->meth->keyfinish(r);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data);\n    CRYPTO_THREAD_lock_free(r->lock);\n    EC_GROUP_free(r->group);\n    EC_POINT_free(r->pub_key);\n    BN_clear_free(r->priv_key);\n    OPENSSL_clear_free((void *)r, sizeof(EC_KEY));\n}', 'int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int i;\n    const BIGNUM *at, *bt;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->top < b->top) {\n        at = b;\n        bt = a;\n    } else {\n        at = a;\n        bt = b;\n    }\n    if (bn_wexpand(r, at->top) == NULL)\n        return 0;\n    for (i = 0; i < bt->top; i++) {\n        r->d[i] = at->d[i] ^ bt->d[i];\n    }\n    for (; i < at->top; i++) {\n        r->d[i] = at->d[i];\n    }\n    r->top = at->top;\n    bn_correct_top(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\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    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}']