crypto/bn/bn_prime.c:306: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_gcd`.
Showing all 16 steps of the trace


crypto/bn/bn_prime.c:249:1: Parameter `ctx->stack.depth`
247.    * returns 0 if there was an error, otherwise it returns 1.
248.    */
249. > int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,
250.                                BN_GENCB *cb, int enhanced, int *status)
251.   {

crypto/bn/bn_prime.c:260:5: Call
258.           return 0;
259.   
260.       BN_CTX_start(ctx);
           ^
261.       g = BN_CTX_get(ctx);
262.       w1 = BN_CTX_get(ctx);

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_prime.c:292:26: Call
290.       /* Montgomery setup for computations mod a */
291.       mont = BN_MONT_CTX_new();
292.       if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))
                                ^
293.           goto err;
294.   

crypto/bn/bn_mont.c:263:1: Parameter `ctx->stack.depth`
  261.   }
  262.   
  263. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
  264.   {
  265.       int i, ret = 0;

crypto/bn/bn_prime.c:306:18: Call
304.           if (enhanced) {
305.               /* (Step 4.3) */
306.               if (!BN_gcd(g, b, w, ctx))
                        ^
307.                   goto err;
308.               /* (Step 4.4) */

crypto/bn/bn_gcd.c:23:5: Call
  21.       bn_check_top(in_b);
  22.   
  23.       BN_CTX_start(ctx);
            ^
  24.       a = BN_CTX_get(ctx);
  25.       b = BN_CTX_get(ctx);

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_gcd.c:49:5: Call
  47.       ret = 1;
  48.    err:
  49.       BN_CTX_end(ctx);
            ^
  50.       bn_check_top(r);
  51.       return ret;

crypto/bn/bn_ctx.c:185:1: Parameter `*ctx->stack.indexes`
    183.   }
    184.   
    185. > void BN_CTX_end(BN_CTX *ctx)
    186.   {
    187.       CTXDBG("ENTER BN_CTX_end()", ctx);

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

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

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

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

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

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

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,\n                             BN_GENCB *cb, int enhanced, int *status)\n{\n    int i, j, a, ret = 0;\n    BIGNUM *g, *w1, *w3, *x, *m, *z, *b;\n    BN_MONT_CTX *mont = NULL;\n    if (!BN_is_odd(w))\n        return 0;\n    BN_CTX_start(ctx);\n    g = BN_CTX_get(ctx);\n    w1 = BN_CTX_get(ctx);\n    w3 = BN_CTX_get(ctx);\n    x = BN_CTX_get(ctx);\n    m = BN_CTX_get(ctx);\n    z = BN_CTX_get(ctx);\n    b = BN_CTX_get(ctx);\n    if (!(b != NULL\n            && BN_copy(w1, w)\n            && BN_sub_word(w1, 1)\n            && BN_copy(w3, w)\n            && BN_sub_word(w3, 3)))\n        goto err;\n    if (BN_is_zero(w3) || BN_is_negative(w3))\n        goto err;\n    a = 1;\n    while (!BN_is_bit_set(w1, a))\n        a++;\n    if (!BN_rshift(m, w1, a))\n        goto err;\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))\n        goto err;\n    if (iterations == BN_prime_checks)\n        iterations = BN_prime_checks_for_size(BN_num_bits(w));\n    for (i = 0; i < iterations; ++i) {\n        if (!BN_priv_rand_range(b, w3) || !BN_add_word(b, 2))\n            goto err;\n        if (enhanced) {\n            if (!BN_gcd(g, b, w, ctx))\n                goto err;\n            if (!BN_is_one(g)) {\n                *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n                ret = 1;\n                goto err;\n            }\n        }\n        if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))\n            goto err;\n        if (BN_is_one(z) || BN_cmp(z, w1) == 0)\n            goto outer_loop;\n        for (j = 1; j < a ; ++j) {\n            if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n                goto err;\n            if (BN_cmp(z, w1) == 0)\n                goto outer_loop;\n            if (BN_is_one(z))\n                goto composite;\n        }\n        if (!BN_GENCB_call(cb, 1, i))\n            goto err;\n        if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n            goto err;\n        if (BN_is_one(z))\n            goto composite;\n        if (!BN_copy(x, z))\n            goto err;\ncomposite:\n        if (enhanced) {\n            if (!BN_sub_word(x, 1) || !BN_gcd(g, x, w, ctx))\n                goto err;\n            if (BN_is_one(g))\n                *status = BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME;\n            else\n                *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n        } else {\n            *status = BN_PRIMETEST_COMPOSITE;\n        }\n        ret = 1;\n        goto err;\nouter_loop: ;\n    }\n    *status = BN_PRIMETEST_PROBABLY_PRIME;\n    ret = 1;\nerr:\n    BN_clear(g);\n    BN_clear(w1);\n    BN_clear(w3);\n    BN_clear(x);\n    BN_clear(m);\n    BN_clear(z);\n    BN_clear(b);\n    BN_CTX_end(ctx);\n    BN_MONT_CTX_free(mont);\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}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n    int i, ret = 0;\n    BIGNUM *Ri, *R;\n    if (BN_is_zero(mod))\n        return 0;\n    BN_CTX_start(ctx);\n    if ((Ri = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    R = &(mont->RR);\n    if (!BN_copy(&(mont->N), mod))\n        goto err;\n    if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n        BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n    mont->N.neg = 0;\n#ifdef MONT_WORD\n    {\n        BIGNUM tmod;\n        BN_ULONG buf[2];\n        bn_init(&tmod);\n        tmod.d = buf;\n        tmod.dmax = 2;\n        tmod.neg = 0;\n        if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n            BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n        mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n        BN_zero(R);\n        if (!(BN_set_bit(R, 2 * BN_BITS2)))\n            goto err;\n        tmod.top = 0;\n        if ((buf[0] = mod->d[0]))\n            tmod.top = 1;\n        if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n            tmod.top = 2;\n        if (BN_is_one(&tmod))\n            BN_zero(Ri);\n        else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n            goto err;\n        if (!BN_is_zero(Ri)) {\n            if (!BN_sub_word(Ri, 1))\n                goto err;\n        } else {\n            if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n                goto err;\n            Ri->neg = 0;\n            Ri->d[0] = BN_MASK2;\n            Ri->d[1] = BN_MASK2;\n            Ri->top = 2;\n        }\n        if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n            goto err;\n        mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n        mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n        BN_zero(R);\n        if (!(BN_set_bit(R, BN_BITS2)))\n            goto err;\n        buf[0] = mod->d[0];\n        buf[1] = 0;\n        tmod.top = buf[0] != 0 ? 1 : 0;\n        if (BN_is_one(&tmod))\n            BN_zero(Ri);\n        else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, BN_BITS2))\n            goto err;\n        if (!BN_is_zero(Ri)) {\n            if (!BN_sub_word(Ri, 1))\n                goto err;\n        } else {\n            if (!BN_set_word(Ri, BN_MASK2))\n                goto err;\n        }\n        if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n            goto err;\n        mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n        mont->n0[1] = 0;\n# endif\n    }\n#else\n    {\n        mont->ri = BN_num_bits(&mont->N);\n        BN_zero(R);\n        if (!BN_set_bit(R, mont->ri))\n            goto err;\n        if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, mont->ri))\n            goto err;\n        if (!BN_sub_word(Ri, 1))\n            goto err;\n        if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n            goto err;\n    }\n#endif\n    BN_zero(&(mont->RR));\n    if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n        goto err;\n    if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n        goto err;\n    for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n        mont->RR.d[i] = 0;\n    mont->RR.top = ret;\n    mont->RR.flags |= BN_FLG_FIXED_TOP;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n    BIGNUM *a, *b, *t;\n    int ret = 0;\n    bn_check_top(in_a);\n    bn_check_top(in_b);\n    BN_CTX_start(ctx);\n    a = BN_CTX_get(ctx);\n    b = BN_CTX_get(ctx);\n    if (b == NULL)\n        goto err;\n    if (BN_copy(a, in_a) == NULL)\n        goto err;\n    if (BN_copy(b, in_b) == NULL)\n        goto err;\n    a->neg = 0;\n    b->neg = 0;\n    if (BN_cmp(a, b) < 0) {\n        t = a;\n        a = b;\n        b = t;\n    }\n    t = euclid(a, b);\n    if (t == NULL)\n        goto err;\n    if (BN_copy(r, t) == NULL)\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(r);\n    return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\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}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']