test/ectest.c:95: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mul`.
Showing all 13 steps of the trace


test/ectest.c:68:13: Call
66.           || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx))
67.           || !TEST_true(EC_POINT_is_at_infinity(group, Q))
68.           || !TEST_true(EC_GROUP_precompute_mult(group, ctx))
                  ^
69.           || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx))
70.           || !TEST_true(EC_POINT_is_at_infinity(group, Q)))

crypto/ec/ec_lib.c:941:1: Parameter `ctx->stack.depth`
  939.   }
  940.   
  941. > int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
  942.   {
  943.       if (group->meth->mul == 0)

test/ectest.c:95:17: Call
93.   
94.               /* n2 = (1 - order) * (1 + order) = 1 - order^2 */
95.               || !TEST_true(BN_mul(n2, n1, n2, ctx))
                      ^
96.               || !TEST_true(EC_POINT_mul(group, Q, NULL, P, n2, ctx))
97.               || !TEST_int_eq(0, EC_POINT_cmp(group, Q, P, ctx)))

crypto/bn/bn_mul.c:521:5: Call
  519.       top = al + bl;
  520.   
  521.       BN_CTX_start(ctx);
             ^
  522.       if ((r == a) || (r == b)) {
  523.           if ((rr = BN_CTX_get(ctx)) == NULL)

crypto/bn/bn_ctx.c:181:1: Parameter `*ctx->stack.indexes`
    179.   }
    180.   
    181. > void BN_CTX_start(BN_CTX *ctx)
    182.   {
    183.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_mul.c:646:5: Call
  644.    err:
  645.       bn_check_top(r);
  646.       BN_CTX_end(ctx);
             ^
  647.       return (ret);
  648.   }

crypto/bn/bn_ctx.c:195:1: Parameter `*ctx->stack.indexes`
    193.   }
    194.   
    195. > void BN_CTX_end(BN_CTX *ctx)
    196.   {
    197.       CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:201:27: Call
    199.           ctx->err_stack--;
    200.       else {
    201.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                     ^
    202.           /* Does this stack frame have anything to release? */
    203.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:271:1: <Offset trace>
269.   }
270.   
271. > static unsigned int BN_STACK_pop(BN_STACK *st)
272.   {
273.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:271:1: Parameter `st->depth`
      269.   }
      270.   
      271. > static unsigned int BN_STACK_pop(BN_STACK *st)
      272.   {
      273.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:271:1: <Length trace>
269.   }
270.   
271. > static unsigned int BN_STACK_pop(BN_STACK *st)
272.   {
273.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:271:1: Parameter `*st->indexes`
      269.   }
      270.   
      271. > static unsigned int BN_STACK_pop(BN_STACK *st)
      272.   {
      273.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:273:12: Array access: Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mul` 
      271.   static unsigned int BN_STACK_pop(BN_STACK *st)
      272.   {
      273.       return st->indexes[--(st->depth)];
                        ^
      274.   }
      275.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static int group_order_tests(EC_GROUP *group)\n{\n    BIGNUM *n1 = NULL, *n2 = NULL, *order = NULL;\n    EC_POINT *P = NULL, *Q = NULL, *R = NULL, *S = NULL;\n    BN_CTX *ctx = NULL;\n    int i = 0, r = 0;\n    if (!TEST_ptr(n1 = BN_new())\n        || !TEST_ptr(n2 = BN_new())\n        || !TEST_ptr(order = BN_new())\n        || !TEST_ptr(ctx = BN_CTX_new())\n        || !TEST_ptr(P = EC_POINT_new(group))\n        || !TEST_ptr(Q = EC_POINT_new(group))\n        || !TEST_ptr(R = EC_POINT_new(group))\n        || !TEST_ptr(S = EC_POINT_new(group)))\n        goto err;\n    if (!TEST_true(EC_GROUP_get_order(group, order, ctx))\n        || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, Q))\n        || !TEST_true(EC_GROUP_precompute_mult(group, ctx))\n        || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, Q)))\n        goto err;\n    for (i = 1; i <= 2; i++) {\n        const BIGNUM *scalars[6];\n        const EC_POINT *points[6];\n        if (!TEST_true(BN_set_word(n1, i))\n            || !TEST_true(EC_POINT_mul(group, P, n1, NULL, NULL, ctx))\n            || !TEST_true(BN_one(n1))\n            || !TEST_true(BN_sub(n1, n1, order))\n            || !TEST_true(EC_POINT_mul(group, Q, NULL, P, n1, ctx))\n            || !TEST_int_eq(0, EC_POINT_cmp(group, Q, P, ctx))\n            || !TEST_true(BN_add(n2, order, BN_value_one()))\n            || !TEST_true(EC_POINT_mul(group, Q, NULL, P, n2, ctx))\n            || !TEST_int_eq(0, EC_POINT_cmp(group, Q, P, ctx))\n            || !TEST_true(BN_mul(n2, n1, n2, ctx))\n            || !TEST_true(EC_POINT_mul(group, Q, NULL, P, n2, ctx))\n            || !TEST_int_eq(0, EC_POINT_cmp(group, Q, P, ctx)))\n            goto err;\n        BN_set_negative(n2, 0);\n        if (!TEST_true(EC_POINT_mul(group, Q, NULL, P, n2, ctx))\n            || !TEST_true(EC_POINT_add(group, Q, Q, P, ctx))\n            || !TEST_true(EC_POINT_is_at_infinity(group, Q))\n            || !TEST_false(EC_POINT_is_at_infinity(group, P)))\n            goto err;\n        scalars[0] = scalars[1] = BN_value_one();\n        points[0]  = points[1]  = P;\n        if (!TEST_true(EC_POINTs_mul(group, R, NULL, 2, points, scalars, ctx))\n            || !TEST_true(EC_POINT_dbl(group, S, points[0], ctx))\n            || !TEST_int_eq(0, EC_POINT_cmp(group, R, S, ctx)))\n            goto err;\n        scalars[0] = n1;\n        points[0] = Q;\n        scalars[1] = n2;\n        points[1] = P;\n        scalars[2] = n1;\n        points[2] = Q;\n        scalars[3] = n2;\n        points[3] = Q;\n        scalars[4] = n1;\n        points[4] = P;\n        scalars[5] = n2;\n        points[5] = Q;\n        if (!TEST_true(EC_POINTs_mul(group, P, NULL, 6, points, scalars, ctx))\n            || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n            goto err;\n    }\n    r = 1;\nerr:\n    if (r == 0 && i != 0)\n        TEST_info(i == 1 ? "allowing precomputation" :\n                           "without precomputation");\n    EC_POINT_free(P);\n    EC_POINT_free(Q);\n    EC_POINT_free(R);\n    EC_POINT_free(S);\n    BN_free(n1);\n    BN_free(n2);\n    BN_free(order);\n    BN_CTX_free(ctx);\n    return r;\n}', 'int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)\n{\n    if (group->meth->mul == 0)\n        return ec_wNAF_precompute_mult(group, ctx);\n    if (group->meth->precompute_mult != 0)\n        return group->meth->precompute_mult(group, ctx);\n    else\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#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    rr->neg = a->neg ^ b->neg;\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_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_start", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_end", ctx);\n    if (ctx->err_stack)\n        ctx->err_stack--;\n    else {\n        unsigned int fp = BN_STACK_pop(&ctx->stack);\n        if (fp < ctx->used)\n            BN_POOL_release(&ctx->pool, ctx->used - fp);\n        ctx->used = fp;\n        ctx->too_many = 0;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']