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


crypto/bn/bn_prime.c:234:5: Call
232.       if (ctx == NULL)
233.           goto err;
234.       BN_CTX_start(ctx);
           ^
235.       t = BN_CTX_get(ctx);
236.       if (!t)

crypto/bn/bn_ctx.c:236:1: Parameter `ctx->stack.depth`
  234.   }
  235.   
  236. > void BN_CTX_start(BN_CTX *ctx)
  237.   {
  238.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_prime.c:245:18: Call
243.       } else {
244.           if (safe) {
245.               if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))
                        ^
246.                   goto err;
247.           } else {

crypto/bn/bn_prime.c:636:5: Call
  634.   
  635.       bits--;
  636.       BN_CTX_start(ctx);
             ^
  637.       t1 = BN_CTX_get(ctx);
  638.       q = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:236:1: Parameter `*ctx->stack.indexes`
    234.   }
    235.   
    236. > void BN_CTX_start(BN_CTX *ctx)
    237.   {
    238.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_prime.c:688:5: Call
  686.   
  687.    err:
  688.       BN_CTX_end(ctx);
             ^
  689.       bn_check_top(p);
  690.       return (ret);

crypto/bn/bn_ctx.c:250:1: Parameter `*ctx->stack.indexes`
    248.   }
    249.   
    250. > void BN_CTX_end(BN_CTX *ctx)
    251.   {
    252.       CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:256:27: Call
    254.           ctx->err_stack--;
    255.       else {
    256.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                     ^
    257.           /* Does this stack frame have anything to release? */
    258.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:326:1: <Offset trace>
324.   }
325.   
326. > static unsigned int BN_STACK_pop(BN_STACK *st)
327.   {
328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:326:1: Parameter `st->depth`
      324.   }
      325.   
      326. > static unsigned int BN_STACK_pop(BN_STACK *st)
      327.   {
      328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:326:1: <Length trace>
324.   }
325.   
326. > static unsigned int BN_STACK_pop(BN_STACK *st)
327.   {
328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:326:1: Parameter `*st->indexes`
      324.   }
      325.   
      326. > static unsigned int BN_STACK_pop(BN_STACK *st)
      327.   {
      328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:328:12: Array access: Offset: [-1, +oo] Size: [1, +oo] by call to `probable_prime_dh_safe` 
      326.   static unsigned int BN_STACK_pop(BN_STACK *st)
      327.   {
      328.       return st->indexes[--(st->depth)];
                        ^
      329.   }
      330.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\n                         const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)\n{\n    BIGNUM *t;\n    int found = 0;\n    int i, j, c1 = 0;\n    BN_CTX *ctx = NULL;\n    prime_t *mods = NULL;\n    int checks = BN_prime_checks_for_size(bits);\n    mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);\n    if (mods == NULL)\n        goto err;\n    if (bits < 2) {\n        BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n        return 0;\n    } else if (bits == 2 && safe) {\n        BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n        return 0;\n    }\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    t = BN_CTX_get(ctx);\n    if (!t)\n        goto err;\n loop:\n    if (add == NULL) {\n        if (!probable_prime(ret, bits, mods))\n            goto err;\n    } else {\n        if (safe) {\n            if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))\n                goto err;\n        } else {\n            if (!bn_probable_prime_dh(ret, bits, add, rem, ctx))\n                goto err;\n        }\n    }\n    if (!BN_GENCB_call(cb, 0, c1++))\n        goto err;\n    if (!safe) {\n        i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);\n        if (i == -1)\n            goto err;\n        if (i == 0)\n            goto loop;\n    } else {\n        if (!BN_rshift1(t, ret))\n            goto err;\n        for (i = 0; i < checks; i++) {\n            j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);\n            if (j == -1)\n                goto err;\n            if (j == 0)\n                goto loop;\n            j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);\n            if (j == -1)\n                goto err;\n            if (j == 0)\n                goto loop;\n            if (!BN_GENCB_call(cb, 2, c1 - 1))\n                goto err;\n        }\n    }\n    found = 1;\n err:\n    OPENSSL_free(mods);\n    if (ctx != NULL)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    bn_check_top(ret);\n    return found;\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}', 'static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,\n                                  const BIGNUM *rem, BN_CTX *ctx)\n{\n    int i, ret = 0;\n    BIGNUM *t1, *qadd, *q;\n    bits--;\n    BN_CTX_start(ctx);\n    t1 = BN_CTX_get(ctx);\n    q = BN_CTX_get(ctx);\n    qadd = BN_CTX_get(ctx);\n    if (qadd == NULL)\n        goto err;\n    if (!BN_rshift1(qadd, padd))\n        goto err;\n    if (!BN_rand(q, bits, 0, 1))\n        goto err;\n    if (!BN_mod(t1, q, qadd, ctx))\n        goto err;\n    if (!BN_sub(q, q, t1))\n        goto err;\n    if (rem == NULL) {\n        if (!BN_add_word(q, 1))\n            goto err;\n    } else {\n        if (!BN_rshift1(t1, rem))\n            goto err;\n        if (!BN_add(q, q, t1))\n            goto err;\n    }\n    if (!BN_lshift1(p, q))\n        goto err;\n    if (!BN_add_word(p, 1))\n        goto err;\n loop:\n    for (i = 1; i < NUMPRIMES; i++) {\n        if ((BN_mod_word(p, (BN_ULONG)primes[i]) == 0) ||\n            (BN_mod_word(q, (BN_ULONG)primes[i]) == 0)) {\n            if (!BN_add(p, p, padd))\n                goto err;\n            if (!BN_add(q, q, qadd))\n                goto err;\n            goto loop;\n        }\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(p);\n    return (ret);\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}']