test/ecdhtest.c:383: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_hex2bn`.
Showing all 14 steps of the trace


test/ecdhtest.c:380:9: Call
378.       EC_POINT *pub = NULL;
379.       const EC_GROUP *grp;
380.       k = EC_KEY_new_by_curve_name(nid);
               ^
381.       if (!k)
382.           goto err;

crypto/ec/ec_key.c:78:19: Call
  76.   EC_KEY *EC_KEY_new_by_curve_name(int nid)
  77.   {
  78.       EC_KEY *ret = EC_KEY_new();
                          ^
  79.       if (ret == NULL)
  80.           return NULL;

crypto/ec/ec_key.c:73:12: Call
    71.   EC_KEY *EC_KEY_new(void)
    72.   {
    73.       return EC_KEY_new_method(NULL);
                     ^
    74.   }
    75.   

crypto/ec/ec_kmeth.c:159:9: Call
      157.       ret->references = 1;
      158.       if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
      159.           EC_KEY_free(ret);
                     ^
      160.           return NULL;
      161.       }

crypto/ec/ec_key.c:94:1: Parameter `r->priv_key->d`
        92.   }
        93.   
        94. > void EC_KEY_free(EC_KEY *r)
        95.   {
        96.       int i;

test/ecdhtest.c:383:9: Call
381.       if (!k)
382.           goto err;
383.       if(!BN_hex2bn(&priv, str))
               ^
384.           goto err;
385.       if (!priv)

crypto/bn/bn_print.c:171:1: Parameter `*(*bn)->d`
  169.   }
  170.   
  171. > int BN_hex2bn(BIGNUM **bn, const char *a)
  172.   {
  173.       BIGNUM *ret = NULL;

crypto/bn/bn_print.c:202:9: Call
  200.   
  201.       /* i is the number of hex digests; */
  202.       if (bn_expand(ret, i * 4) == NULL)
                 ^
  203.           goto err;
  204.   

crypto/bn/bn_lib.c:380:1: Parameter `*b->d`
    378.    */
    379.   
    380. > BIGNUM *bn_expand2(BIGNUM *b, int words)
    381.   {
    382.       bn_check_top(b);

crypto/bn/bn_lib.c:385:23: Call
    383.   
    384.       if (words > b->dmax) {
    385.           BN_ULONG *a = bn_expand_internal(b, words);
                                 ^
    386.           if (!a)
    387.               return NULL;

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

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

crypto/bn/bn_lib.c:325:5: Assignment
      323.   
      324.   #if 1
      325.       B = b->d;
                 ^
      326.       /* Check if the previous number needs to be copied */
      327.       if (B != NULL) {

crypto/bn/bn_lib.c:342:18: Array access: Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_hex2bn` 
      340.               a1 = B[1];
      341.               a2 = B[2];
      342.               a3 = B[3];
                              ^
      343.               A[0] = a0;
      344.               A[1] = a1;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *A, *a = NULL;
    const BN_ULONG *B;
    int i;
    bn_check_top(b);
    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 = A = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = A = OPENSSL_zalloc(words * sizeof(*a));
    if (A == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
#if 1
    B = b->d;
    if (B != NULL) {
        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
            BN_ULONG a0, a1, a2, a3;
            a0 = B[0];
            a1 = B[1];
            a2 = B[2];
            a3 = B[3];
            A[0] = a0;
            A[1] = a1;
            A[2] = a2;
            A[3] = a3;
        }
        switch (b->top & 3) {
        case 3:
            A[2] = B[2];
        case 2:
            A[1] = B[1];
        case 1:
            A[0] = B[0];
        case 0:
            ;
        }
    }
#else
    memset(A, 0, sizeof(*A) * words);
    memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
    return (a);
}
['static EC_KEY *mk_eckey(int nid, const char *str)\n{\n    int ok = 0;\n    EC_KEY *k = NULL;\n    BIGNUM *priv = NULL;\n    EC_POINT *pub = NULL;\n    const EC_GROUP *grp;\n    k = EC_KEY_new_by_curve_name(nid);\n    if (!k)\n        goto err;\n    if(!BN_hex2bn(&priv, str))\n        goto err;\n    if (!priv)\n        goto err;\n    if (!EC_KEY_set_private_key(k, priv))\n        goto err;\n    grp = EC_KEY_get0_group(k);\n    pub = EC_POINT_new(grp);\n    if (!pub)\n        goto err;\n    if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))\n        goto err;\n    if (!EC_KEY_set_public_key(k, pub))\n        goto err;\n    ok = 1;\n err:\n    BN_clear_free(priv);\n    EC_POINT_free(pub);\n    if (ok)\n        return k;\n    EC_KEY_free(k);\n    return NULL;\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    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) {\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            OPENSSL_free(ret);\n            return NULL;\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            ENGINE_finish(ret->engine);\n            OPENSSL_free(ret);\n            return NULL;\n        }\n    }\n#endif\n    ret->version = 1;\n    ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;\n    ret->references = 1;\n    if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {\n        EC_KEY_free(ret);\n        return NULL;\n    }\n    return ret;\n}', 'void EC_KEY_free(EC_KEY *r)\n{\n    int i;\n    if (r == NULL)\n        return;\n    i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC);\n#ifdef REF_PRINT\n    REF_PRINT("EC_KEY", r);\n#endif\n    if (i > 0)\n        return;\n#ifdef REF_CHECK\n    if (i < 0) {\n        fprintf(stderr, "EC_KEY_free, bad reference count\\n");\n        abort();\n    }\n#endif\n    if (r->meth->finish != NULL)\n        r->meth->finish(r);\n#ifndef OPENSSL_NO_ENGINE\n    if (r->engine != NULL)\n        ENGINE_finish(r->engine);\n#endif\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data);\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_hex2bn(BIGNUM **bn, const char *a)\n{\n    BIGNUM *ret = NULL;\n    BN_ULONG l = 0;\n    int neg = 0, h, m, i, j, k, c;\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; isxdigit((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 = i;\n    m = 0;\n    h = 0;\n    while (j > 0) {\n        m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;\n        l = 0;\n        for (;;) {\n            c = a[j - m];\n            if ((c >= '0') && (c <= '9'))\n                k = c - '0';\n            else if ((c >= 'a') && (c <= 'f'))\n                k = c - 'a' + 10;\n            else if ((c >= 'A') && (c <= 'F'))\n                k = c - 'A' + 10;\n            else\n                k = 0;\n            l = (l << 4) | k;\n            if (--m <= 0) {\n                ret->d[h++] = l;\n                break;\n            }\n        }\n        j -= (BN_BYTES * 2);\n    }\n    ret->top = h;\n    bn_correct_top(ret);\n    ret->neg = neg;\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}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *A, *a = NULL;\n    const BN_ULONG *B;\n    int i;\n    bn_check_top(b);\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 = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = 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#if 1\n    B = b->d;\n    if (B != NULL) {\n        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n            BN_ULONG a0, a1, a2, a3;\n            a0 = B[0];\n            a1 = B[1];\n            a2 = B[2];\n            a3 = B[3];\n            A[0] = a0;\n            A[1] = a1;\n            A[2] = a2;\n            A[3] = a3;\n        }\n        switch (b->top & 3) {\n        case 3:\n            A[2] = B[2];\n        case 2:\n            A[1] = B[1];\n        case 1:\n            A[0] = B[0];\n        case 0:\n            ;\n        }\n    }\n#else\n    memset(A, 0, sizeof(*A) * words);\n    memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    return (a);\n}']