test/bntest.c:832: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_GF2m_mod_div`.
Showing all 35 steps of the trace


test/bntest.c:832:19: Call
830.               goto err;
831.           for (j = 0; j < 2; j++) {
832.               if (!(TEST_true(BN_GF2m_mod_div(d, a, c, b[j], ctx))
                         ^
833.                       && TEST_true(BN_GF2m_mod_mul(e, d, c, b[j], ctx))
834.                       && TEST_true(BN_GF2m_mod_div(f, a, e, b[j], ctx))

crypto/bn/bn_gf2m.c:790:1: Parameter `ctx->stack.depth`
  788.    * or y, x could equal y.
  789.    */
  790. > int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,
  791.                       const BIGNUM *p, BN_CTX *ctx)
  792.   {

crypto/bn/bn_gf2m.c:800:5: Call
  798.       bn_check_top(p);
  799.   
  800.       BN_CTX_start(ctx);
             ^
  801.       xinv = BN_CTX_get(ctx);
  802.       if (xinv == NULL)

crypto/bn/bn_ctx.c:171:1: Parameter `ctx->stack.depth`
    169.   }
    170.   
    171. > void BN_CTX_start(BN_CTX *ctx)
    172.   {
    173.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_gf2m.c:813:5: Call
  811.   
  812.    err:
  813.       BN_CTX_end(ctx);
             ^
  814.       return ret;
  815.   }

crypto/bn/bn_ctx.c:185:1: Parameter `ctx->stack.depth`
    183.   }
    184.   
    185. > void BN_CTX_end(BN_CTX *ctx)
    186.   {
    187.       if (ctx == NULL)

test/bntest.c:833:24: Call
831.           for (j = 0; j < 2; j++) {
832.               if (!(TEST_true(BN_GF2m_mod_div(d, a, c, b[j], ctx))
833.                       && TEST_true(BN_GF2m_mod_mul(e, d, c, b[j], ctx))
                              ^
834.                       && TEST_true(BN_GF2m_mod_div(f, a, e, b[j], ctx))
835.                       /* Test that ((a/c)*c)/a = 1. */

crypto/bn/bn_gf2m.c:465:1: Parameter `ctx->stack.depth`
  463.    * BN_GF2m_mod_mul_arr function.
  464.    */
  465. > int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
  466.                       const BIGNUM *p, BN_CTX *ctx)
  467.   {

test/bntest.c:834:24: Call
832.               if (!(TEST_true(BN_GF2m_mod_div(d, a, c, b[j], ctx))
833.                       && TEST_true(BN_GF2m_mod_mul(e, d, c, b[j], ctx))
834.                       && TEST_true(BN_GF2m_mod_div(f, a, e, b[j], ctx))
                              ^
835.                       /* Test that ((a/c)*c)/a = 1. */
836.                       && TEST_BN_eq_one(f)))

crypto/bn/bn_gf2m.c:790:1: Parameter `ctx->stack.depth`
  788.    * or y, x could equal y.
  789.    */
  790. > int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,
  791.                       const BIGNUM *p, BN_CTX *ctx)
  792.   {

crypto/bn/bn_gf2m.c:800:5: Call
  798.       bn_check_top(p);
  799.   
  800.       BN_CTX_start(ctx);
             ^
  801.       xinv = BN_CTX_get(ctx);
  802.       if (xinv == NULL)

crypto/bn/bn_ctx.c:171:1: Parameter `ctx->stack.depth`
    169.   }
    170.   
    171. > void BN_CTX_start(BN_CTX *ctx)
    172.   {
    173.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_gf2m.c:813:5: Call
  811.   
  812.    err:
  813.       BN_CTX_end(ctx);
             ^
  814.       return ret;
  815.   }

crypto/bn/bn_ctx.c:185:1: Parameter `ctx->stack.depth`
    183.   }
    184.   
    185. > void BN_CTX_end(BN_CTX *ctx)
    186.   {
    187.       if (ctx == NULL)

test/bntest.c:832:19: Call
830.               goto err;
831.           for (j = 0; j < 2; j++) {
832.               if (!(TEST_true(BN_GF2m_mod_div(d, a, c, b[j], ctx))
                         ^
833.                       && TEST_true(BN_GF2m_mod_mul(e, d, c, b[j], ctx))
834.                       && TEST_true(BN_GF2m_mod_div(f, a, e, b[j], ctx))

crypto/bn/bn_gf2m.c:790:1: Parameter `ctx->stack.depth`
  788.    * or y, x could equal y.
  789.    */
  790. > int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,
  791.                       const BIGNUM *p, BN_CTX *ctx)
  792.   {

crypto/bn/bn_gf2m.c:800:5: Call
  798.       bn_check_top(p);
  799.   
  800.       BN_CTX_start(ctx);
             ^
  801.       xinv = BN_CTX_get(ctx);
  802.       if (xinv == NULL)

crypto/bn/bn_ctx.c:171:1: Parameter `ctx->stack.depth`
    169.   }
    170.   
    171. > void BN_CTX_start(BN_CTX *ctx)
    172.   {
    173.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_gf2m.c:805:10: Call
  803.           goto err;
  804.   
  805.       if (!BN_GF2m_mod_inv(xinv, x, p, ctx))
                  ^
  806.           goto err;
  807.       if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))

crypto/bn/bn_gf2m.c:724:1: Parameter `ctx->stack.depth`
    722.    * But it does eliminate first order deduction on the input.
    723.    */
    724. > int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
    725.   {
    726.       BIGNUM *b = NULL;

crypto/bn/bn_gf2m.c:729:5: Call
    727.       int ret = 0;
    728.   
    729.       BN_CTX_start(ctx);
               ^
    730.       if ((b = BN_CTX_get(ctx)) == NULL)
    731.           goto err;

crypto/bn/bn_ctx.c:171:1: Parameter `ctx->stack.depth`
      169.   }
      170.   
      171. > void BN_CTX_start(BN_CTX *ctx)
      172.   {
      173.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_gf2m.c:741:10: Call
    739.   
    740.       /* r := a * b */
    741.       if (!BN_GF2m_mod_mul(r, a, b, p, ctx))
                    ^
    742.           goto err;
    743.   

crypto/bn/bn_gf2m.c:465:1: Parameter `ctx->stack.depth`
      463.    * BN_GF2m_mod_mul_arr function.
      464.    */
      465. > int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
      466.                       const BIGNUM *p, BN_CTX *ctx)
      467.   {

crypto/bn/bn_gf2m.c:481:11: Call
      479.           goto err;
      480.       }
      481.       ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
                       ^
      482.       bn_check_top(r);
      483.    err:

crypto/bn/bn_gf2m.c:424:5: Call
        422.       }
        423.   
        424.       BN_CTX_start(ctx);
                   ^
        425.       if ((s = BN_CTX_get(ctx)) == NULL)
        426.           goto err;

crypto/bn/bn_ctx.c:171:1: Parameter `*ctx->stack.indexes`
          169.   }
          170.   
          171. > void BN_CTX_start(BN_CTX *ctx)
          172.   {
          173.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_gf2m.c:454:5: Call
        452.   
        453.    err:
        454.       BN_CTX_end(ctx);
                   ^
        455.       return ret;
        456.   }

crypto/bn/bn_ctx.c:185:1: Parameter `*ctx->stack.indexes`
          183.   }
          184.   
          185. > void BN_CTX_end(BN_CTX *ctx)
          186.   {
          187.       if (ctx == NULL)

crypto/bn/bn_ctx.c:193:27: Call
          191.           ctx->err_stack--;
          192.       else {
          193.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                           ^
          194.           /* Does this stack frame have anything to release? */
          195.           if (fp < ctx->used)

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

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

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

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

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

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static int test_gf2m_moddiv(void)\n{\n    BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL;\n    BIGNUM *e = NULL, *f = NULL;\n    int i, j, st = 0;\n    if (!TEST_ptr(a = BN_new())\n            || !TEST_ptr(b[0] = BN_new())\n            || !TEST_ptr(b[1] = BN_new())\n            || !TEST_ptr(c = BN_new())\n            || !TEST_ptr(d = BN_new())\n            || !TEST_ptr(e = BN_new())\n            || !TEST_ptr(f = BN_new()))\n        goto err;\n    if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0]))\n            && TEST_true(BN_GF2m_arr2poly(p1, b[1]))))\n        goto err;\n    for (i = 0; i < NUM0; i++) {\n        if (!(TEST_true(BN_bntest_rand(a, 512, 0, 0))\n                && TEST_true(BN_bntest_rand(c, 512, 0, 0))))\n            goto err;\n        for (j = 0; j < 2; j++) {\n            if (!(TEST_true(BN_GF2m_mod_div(d, a, c, b[j], ctx))\n                    && TEST_true(BN_GF2m_mod_mul(e, d, c, b[j], ctx))\n                    && TEST_true(BN_GF2m_mod_div(f, a, e, b[j], ctx))\n                    && TEST_BN_eq_one(f)))\n                goto err;\n        }\n    }\n    st = 1;\n err:\n    BN_free(a);\n    BN_free(b[0]);\n    BN_free(b[1]);\n    BN_free(c);\n    BN_free(d);\n    BN_free(e);\n    BN_free(f);\n    return st;\n}', 'int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,\n                    const BIGNUM *p, BN_CTX *ctx)\n{\n    BIGNUM *xinv = NULL;\n    int ret = 0;\n    bn_check_top(y);\n    bn_check_top(x);\n    bn_check_top(p);\n    BN_CTX_start(ctx);\n    xinv = BN_CTX_get(ctx);\n    if (xinv == NULL)\n        goto err;\n    if (!BN_GF2m_mod_inv(xinv, x, p, ctx))\n        goto err;\n    if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG("ENTER 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("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    if (ctx == NULL)\n        return;\n    CTXDBG("ENTER 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("LEAVE BN_CTX_end()", ctx);\n}', 'int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                    const BIGNUM *p, BN_CTX *ctx)\n{\n    int ret = 0;\n    const int max = BN_num_bits(p) + 1;\n    int *arr = NULL;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(p);\n    if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)\n        goto err;\n    ret = BN_GF2m_poly2arr(p, arr, max);\n    if (!ret || ret > max) {\n        BNerr(BN_F_BN_GF2M_MOD_MUL, BN_R_INVALID_LENGTH);\n        goto err;\n    }\n    ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);\n    bn_check_top(r);\n err:\n    OPENSSL_free(arr);\n    return ret;\n}', 'int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n    BIGNUM *b = NULL;\n    int ret = 0;\n    BN_CTX_start(ctx);\n    if ((b = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    do {\n        if (!BN_priv_rand(b, BN_num_bits(p) - 1,\n                          BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n            goto err;\n    } while (BN_is_zero(b));\n    if (!BN_GF2m_mod_mul(r, a, b, p, ctx))\n        goto err;\n    if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx))\n        goto err;\n    if (!BN_GF2m_mod_mul(r, r, b, p, ctx))\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                        const int p[], BN_CTX *ctx)\n{\n    int zlen, i, j, k, ret = 0;\n    BIGNUM *s;\n    BN_ULONG x1, x0, y1, y0, zz[4];\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a == b) {\n        return BN_GF2m_mod_sqr_arr(r, a, p, ctx);\n    }\n    BN_CTX_start(ctx);\n    if ((s = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    zlen = a->top + b->top + 4;\n    if (!bn_wexpand(s, zlen))\n        goto err;\n    s->top = zlen;\n    for (i = 0; i < zlen; i++)\n        s->d[i] = 0;\n    for (j = 0; j < b->top; j += 2) {\n        y0 = b->d[j];\n        y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];\n        for (i = 0; i < a->top; i += 2) {\n            x0 = a->d[i];\n            x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];\n            bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);\n            for (k = 0; k < 4; k++)\n                s->d[i + j + k] ^= zz[k];\n        }\n    }\n    bn_correct_top(s);\n    if (BN_GF2m_mod_arr(r, s, p))\n        ret = 1;\n    bn_check_top(r);\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']