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


crypto/ec/ecdh_ossl.c:110:9: Call
108.           goto err;
109.       BN_CTX_start(ctx);
110.       x = BN_CTX_get(ctx);
               ^
111.       y = BN_CTX_get(ctx);
112.   

crypto/bn/bn_ctx.c:284:5: Call
  282.       }
  283.       /* OK, make sure the returned bignum is "zero" */
  284.       BN_zero(ret);
             ^
  285.       ctx->used++;
  286.       CTXDBG_RET(ctx, ret);

crypto/bn/bn_lib.c:530:1: Parameter `*a->d`
    528.   }
    529.   
    530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
    531.   {
    532.       bn_check_top(a);

crypto/ec/ecdh_ossl.c:123:14: Call
121.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
122.           if (!EC_GROUP_get_cofactor(group, x, ctx) ||
123.               !BN_mul(x, x, priv_key, ctx)) {
                    ^
124.               ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);
125.               goto err;

crypto/bn/bn_mul.c:883:1: Parameter `a->top`
  881.   #endif                          /* BN_RECURSION */
  882.   
  883. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  884.   {
  885.       int ret = 0;

crypto/bn/bn_mul.c:900:5: Assignment
  898.       bn_check_top(r);
  899.   
  900.       al = a->top;
             ^
  901.       bl = b->top;
  902.   

crypto/bn/bn_mul.c:972:17: Call
  970.                   if (bn_wexpand(rr, k * 2) == NULL)
  971.                       goto err;
  972.                   bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);
                         ^
  973.               }
  974.               rr->top = top;

crypto/bn/bn_mul.c:387:1: <Offset trace>
385.    */
386.   /* dnX may not be positive, but n2/2+dnX has to be */
387. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
388.                         int dna, int dnb, BN_ULONG *t)
389.   {

crypto/bn/bn_mul.c:387:1: Parameter `n2`
    385.    */
    386.   /* dnX may not be positive, but n2/2+dnX has to be */
    387. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
    388.                         int dna, int dnb, BN_ULONG *t)
    389.   {

crypto/bn/bn_mul.c:387:1: <Length trace>
385.    */
386.   /* dnX may not be positive, but n2/2+dnX has to be */
387. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
388.                         int dna, int dnb, BN_ULONG *t)
389.   {

crypto/bn/bn_mul.c:387:1: Parameter `*t`
    385.    */
    386.   /* dnX may not be positive, but n2/2+dnX has to be */
    387. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
    388.                         int dna, int dnb, BN_ULONG *t)
    389.   {

crypto/bn/bn_mul.c:478:9: Array access: Offset: [32, +oo] Size: [0, 8388607] by call to `BN_mul` 
    476.   # endif                         /* BN_MUL_COMBA */
    477.       {
    478.           p = &(t[n2 * 2]);
                   ^
    479.           if (!zero)
    480.               bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);

void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
                      int dna, int dnb, BN_ULONG *t)
{
    int n = n2 / 2, c1, c2;
    int tna = n + dna, tnb = n + dnb;
    unsigned int neg, zero;
    BN_ULONG ln, lo, *p;
# ifdef BN_MUL_COMBA
#  if 0
    if (n2 == 4) {
        bn_mul_comba4(r, a, b);
        return;
    }
#  endif
    if (n2 == 8 && dna == 0 && dnb == 0) {
        bn_mul_comba8(r, a, b);
        return;
    }
# endif
    if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {
        bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);
        if ((dna + dnb) < 0)
            memset(&r[2 * n2 + dna + dnb], 0,
                   sizeof(BN_ULONG) * -(dna + dnb));
        return;
    }
    c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);
    c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);
    zero = neg = 0;
    switch (c1 * 3 + c2) {
    case -4:
        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);
        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);
        break;
    case -3:
        zero = 1;
        break;
    case -2:
        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);
        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
        neg = 1;
        break;
    case -1:
    case 0:
    case 1:
        zero = 1;
        break;
    case 2:
        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);
        neg = 1;
        break;
    case 3:
        zero = 1;
        break;
    case 4:
        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
        break;
    }
# ifdef BN_MUL_COMBA
    if (n == 4 && dna == 0 && dnb == 0) {
        if (!zero)
            bn_mul_comba4(&(t[n2]), t, &(t[n]));
        else
            memset(&t[n2], 0, sizeof(*t) * 8);
        bn_mul_comba4(r, a, b);
        bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));
    } else if (n == 8 && dna == 0 && dnb == 0) {
        if (!zero)
            bn_mul_comba8(&(t[n2]), t, &(t[n]));
        else
            memset(&t[n2], 0, sizeof(*t) * 16);
        bn_mul_comba8(r, a, b);
        bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));
    } else
# endif
    {
        p = &(t[n2 * 2]);
        if (!zero)
            bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
        else
            memset(&t[n2], 0, sizeof(*t) * n2);
        bn_mul_recursive(r, a, b, n, 0, 0, p);
        bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);
    }
    c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));
    if (neg) {
        c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));
    } else {
        c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));
    }
    c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));
    if (c1) {
        p = &(r[n + n2]);
        lo = *p;
        ln = (lo + c1) & BN_MASK2;
        *p = ln;
        if (ln < (BN_ULONG)c1) {
            do {
                p++;
                lo = *p;
                ln = (lo + 1) & BN_MASK2;
                *p = ln;
            } while (ln == 0);
        }
    }
}
['int ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,\n                          const EC_KEY *ecdh,\n                          void *(*KDF) (const void *in, size_t inlen,\n                                        void *out, size_t *outlen))\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 = -1;\n    size_t buflen, len;\n    unsigned char *buf = NULL;\n    if (outlen > INT_MAX) {\n        ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);\n        return -1;\n    }\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_OSSL_ECDH_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, ctx) ||\n            !BN_mul(x, x, priv_key, ctx)) {\n            ECerr(EC_F_OSSL_ECDH_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_OSSL_ECDH_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_OSSL_ECDH_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_OSSL_ECDH_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_OSSL_ECDH_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_OSSL_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if ((buf = OPENSSL_malloc(buflen)) == NULL) {\n        ECerr(EC_F_OSSL_ECDH_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_OSSL_ECDH_COMPUTE_KEY, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (KDF != 0) {\n        if (KDF(buf, buflen, out, &outlen) == NULL) {\n            ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, EC_R_KDF_FAILED);\n            goto err;\n        }\n        ret = outlen;\n    } else {\n        if (outlen > buflen)\n            outlen = buflen;\n        memcpy(out, buf, outlen);\n        ret = outlen;\n    }\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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\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)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    bn_check_top(r);\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n                      int dna, int dnb, BN_ULONG *t)\n{\n    int n = n2 / 2, c1, c2;\n    int tna = n + dna, tnb = n + dnb;\n    unsigned int neg, zero;\n    BN_ULONG ln, lo, *p;\n# ifdef BN_MUL_COMBA\n#  if 0\n    if (n2 == 4) {\n        bn_mul_comba4(r, a, b);\n        return;\n    }\n#  endif\n    if (n2 == 8 && dna == 0 && dnb == 0) {\n        bn_mul_comba8(r, a, b);\n        return;\n    }\n# endif\n    if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n        bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);\n        if ((dna + dnb) < 0)\n            memset(&r[2 * n2 + dna + dnb], 0,\n                   sizeof(BN_ULONG) * -(dna + dnb));\n        return;\n    }\n    c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n    c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n    zero = neg = 0;\n    switch (c1 * 3 + c2) {\n    case -4:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        break;\n    case -3:\n        zero = 1;\n        break;\n    case -2:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        neg = 1;\n        break;\n    case -1:\n    case 0:\n    case 1:\n        zero = 1;\n        break;\n    case 2:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        neg = 1;\n        break;\n    case 3:\n        zero = 1;\n        break;\n    case 4:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        break;\n    }\n# ifdef BN_MUL_COMBA\n    if (n == 4 && dna == 0 && dnb == 0) {\n        if (!zero)\n            bn_mul_comba4(&(t[n2]), t, &(t[n]));\n        else\n            memset(&t[n2], 0, sizeof(*t) * 8);\n        bn_mul_comba4(r, a, b);\n        bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));\n    } else if (n == 8 && dna == 0 && dnb == 0) {\n        if (!zero)\n            bn_mul_comba8(&(t[n2]), t, &(t[n]));\n        else\n            memset(&t[n2], 0, sizeof(*t) * 16);\n        bn_mul_comba8(r, a, b);\n        bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));\n    } else\n# endif\n    {\n        p = &(t[n2 * 2]);\n        if (!zero)\n            bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n        else\n            memset(&t[n2], 0, sizeof(*t) * n2);\n        bn_mul_recursive(r, a, b, n, 0, 0, p);\n        bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);\n    }\n    c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n    if (neg) {\n        c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n    } else {\n        c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n    }\n    c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n    if (c1) {\n        p = &(r[n + n2]);\n        lo = *p;\n        ln = (lo + c1) & BN_MASK2;\n        *p = ln;\n        if (ln < (BN_ULONG)c1) {\n            do {\n                p++;\n                lo = *p;\n                ln = (lo + 1) & BN_MASK2;\n                *p = ln;\n            } while (ln == 0);\n        }\n    }\n}']