crypto/ec/ecdh_ossl.c:80: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_mul`.
Showing all 11 steps of the trace


crypto/ec/ecdh_ossl.c:79:14: Call
77.   
78.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
79.           if (!EC_GROUP_get_cofactor(group, x, NULL) ||
                   ^
80.               !BN_mul(x, x, priv_key, ctx)) {
81.               ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);

crypto/ec/ec_lib.c:342:1: Parameter `cofactor->d`
  340.   }
  341.   
  342. > int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
  343.                             BN_CTX *ctx)
  344.   {

crypto/ec/ecdh_ossl.c:80:14: Call
78.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
79.           if (!EC_GROUP_get_cofactor(group, x, NULL) ||
80.               !BN_mul(x, x, priv_key, ctx)) {
                   ^
81.               ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);
82.               goto err;

crypto/bn/bn_mul.c:879:13: Assignment
  877.               if (bn_wexpand(rr, 16) == NULL)
  878.                   goto err;
  879.               rr->top = 16;
                     ^
  880.               bn_mul_comba8(rr->d, a->d, b->d);
  881.               goto end;

crypto/bn/bn_mul.c:972:5: Call
  970.    end:
  971.   #endif
  972.       bn_correct_top(rr);
             ^
  973.       if (r != rr && BN_copy(r, rr) == NULL)
  974.           goto err;

crypto/bn/bn_lib.c:1021:1: <Offset trace>
1019.   }
1020.   
1021. > void bn_correct_top(BIGNUM *a)
1022.   {
1023.       BN_ULONG *ftl;

crypto/bn/bn_lib.c:1021:1: Parameter `a->top`
    1019.   }
    1020.   
    1021. > void bn_correct_top(BIGNUM *a)
    1022.   {
    1023.       BN_ULONG *ftl;

crypto/bn/bn_lib.c:1024:5: Assignment
    1022.   {
    1023.       BN_ULONG *ftl;
    1024.       int tmp_top = a->top;
                ^
    1025.   
    1026.       if (tmp_top > 0) {

crypto/bn/bn_lib.c:1021:1: <Length trace>
1019.   }
1020.   
1021. > void bn_correct_top(BIGNUM *a)
1022.   {
1023.       BN_ULONG *ftl;

crypto/bn/bn_lib.c:1021:1: Parameter `*a->d`
    1019.   }
    1020.   
    1021. > void bn_correct_top(BIGNUM *a)
    1022.   {
    1023.       BN_ULONG *ftl;

crypto/bn/bn_lib.c:1027:14: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_mul` 
    1025.   
    1026.       if (tmp_top > 0) {
    1027.           for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {
                         ^
    1028.               ftl--;
    1029.               if (*ftl != 0)

void bn_correct_top(BIGNUM *a)
{
    BN_ULONG *ftl;
    int tmp_top = a->top;
    if (tmp_top > 0) {
        for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {
            ftl--;
            if (*ftl != 0)
                break;
        }
        a->top = tmp_top;
    }
    if (a->top == 0)
        a->neg = 0;
    bn_pollute(a);
}
['int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen,\n                            const EC_POINT *pub_key, const EC_KEY *ecdh)\n{\n    BN_CTX *ctx;\n    EC_POINT *tmp = NULL;\n    BIGNUM *x = NULL, *y = NULL;\n    const BIGNUM *priv_key;\n    const EC_GROUP *group;\n    int ret = 0;\n    size_t buflen, len;\n    unsigned char *buf = NULL;\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    x = BN_CTX_get(ctx);\n    y = BN_CTX_get(ctx);\n    priv_key = EC_KEY_get0_private_key(ecdh);\n    if (priv_key == NULL) {\n        ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_NO_PRIVATE_VALUE);\n        goto err;\n    }\n    group = EC_KEY_get0_group(ecdh);\n    if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {\n        if (!EC_GROUP_get_cofactor(group, x, NULL) ||\n            !BN_mul(x, x, priv_key, ctx)) {\n            ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        priv_key = x;\n    }\n    if ((tmp = EC_POINT_new(group)) == NULL) {\n        ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) {\n        ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_POINT_ARITHMETIC_FAILURE);\n        goto err;\n    }\n    if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==\n        NID_X9_62_prime_field) {\n        if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, ctx)) {\n            ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_POINT_ARITHMETIC_FAILURE);\n            goto err;\n        }\n    }\n#ifndef OPENSSL_NO_EC2M\n    else {\n        if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx)) {\n            ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_POINT_ARITHMETIC_FAILURE);\n            goto err;\n        }\n    }\n#endif\n    buflen = (EC_GROUP_get_degree(group) + 7) / 8;\n    len = BN_num_bytes(x);\n    if (len > buflen) {\n        ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if ((buf = OPENSSL_malloc(buflen)) == NULL) {\n        ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    memset(buf, 0, buflen - len);\n    if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) {\n        ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_BN_LIB);\n        goto err;\n    }\n    *pout = buf;\n    *poutlen = buflen;\n    buf = NULL;\n    ret = 1;\n err:\n    EC_POINT_free(tmp);\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    OPENSSL_free(buf);\n    return ret;\n}', 'int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,\n                          BN_CTX *ctx)\n{\n    if (group->cofactor == NULL)\n        return 0;\n    if (!BN_copy(cofactor, group->cofactor))\n        return 0;\n    return !BN_is_zero(group->cofactor);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = 0;\n    int top, al, bl;\n    BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    int i;\n#endif\n#ifdef BN_RECURSION\n    BIGNUM *t = NULL;\n    int j = 0, k;\n#endif\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(r);\n    al = a->top;\n    bl = b->top;\n    if ((al == 0) || (bl == 0)) {\n        BN_zero(r);\n        return (1);\n    }\n    top = al + bl;\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == b)) {\n        if ((rr = BN_CTX_get(ctx)) == NULL)\n            goto err;\n    } else\n        rr = r;\n    rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n    if (i == 0) {\n# if 0\n        if (al == 4) {\n            if (bn_wexpand(rr, 8) == NULL)\n                goto err;\n            rr->top = 8;\n            bn_mul_comba4(rr->d, a->d, b->d);\n            goto end;\n        }\n# endif\n        if (al == 8) {\n            if (bn_wexpand(rr, 16) == NULL)\n                goto err;\n            rr->top = 16;\n            bn_mul_comba8(rr->d, a->d, b->d);\n            goto end;\n        }\n    }\n#endif\n#ifdef BN_RECURSION\n    if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n        if (i >= -1 && i <= 1) {\n            if (i >= 0) {\n                j = BN_num_bits_word((BN_ULONG)al);\n            }\n            if (i == -1) {\n                j = BN_num_bits_word((BN_ULONG)bl);\n            }\n            j = 1 << (j - 1);\n            assert(j <= al || j <= bl);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (t == NULL)\n                goto err;\n            if (al > j || bl > j) {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d,\n                                      j, al - j, bl - j, t->d);\n            } else {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n# if 0\n        if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n            BIGNUM *tmp_bn = (BIGNUM *)b;\n            if (bn_wexpand(tmp_bn, al) == NULL)\n                goto err;\n            tmp_bn->d[bl] = 0;\n            bl++;\n            i--;\n        } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n            BIGNUM *tmp_bn = (BIGNUM *)a;\n            if (bn_wexpand(tmp_bn, bl) == NULL)\n                goto err;\n            tmp_bn->d[al] = 0;\n            al++;\n            i++;\n        }\n        if (i == 0) {\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (al == j) {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n            } else {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n# endif\n    }\n#endif\n    if (bn_wexpand(rr, top) == NULL)\n        goto err;\n    rr->top = top;\n    bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n    bn_correct_top(rr);\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\n    ret = 1;\n err:\n    bn_check_top(r);\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'void bn_correct_top(BIGNUM *a)\n{\n    BN_ULONG *ftl;\n    int tmp_top = a->top;\n    if (tmp_top > 0) {\n        for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {\n            ftl--;\n            if (*ftl != 0)\n                break;\n        }\n        a->top = tmp_top;\n    }\n    if (a->top == 0)\n        a->neg = 0;\n    bn_pollute(a);\n}']