crypto/dsa/dsa_ossl.c:183: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mod_mul`.
Showing all 17 steps of the trace


crypto/dsa/dsa_ossl.c:162:14: Call
160.    redo:
161.       if ((dsa->kinv == NULL) || (dsa->r == NULL)) {
162.           if (!dsa_sign_setup(dsa, ctx, &kinv, &r, dgst, dlen))
                    ^
163.               goto err;
164.       } else {

crypto/dsa/dsa_ossl.c:229:1: Parameter `ctx_in->stack.depth`
  227.   }
  228.   
  229. > static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,
  230.                             BIGNUM **kinvp, BIGNUM **rp,
  231.                             const unsigned char *dgst, int dlen)

crypto/dsa/dsa_ossl.c:183:10: Call
181.   
182.       /* Compute  s = inv(k) (m + xr) mod q */
183.       if (!BN_mod_mul(xr, dsa->priv_key, r, dsa->q, ctx))
                ^
184.           goto err;               /* s = xr */
185.       if (!BN_add(s, xr, m))

crypto/bn/bn_mod.c:178:1: Parameter `ctx->stack.depth`
  176.   
  177.   /* slow but works */
  178. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  179.                  BN_CTX *ctx)
  180.   {

crypto/bn/bn_mod.c:188:5: Call
  186.       bn_check_top(m);
  187.   
  188.       BN_CTX_start(ctx);
             ^
  189.       if ((t = BN_CTX_get(ctx)) == NULL)
  190.           goto err;

crypto/bn/bn_ctx.c:227:1: Parameter `ctx->stack.depth`
    225.   }
    226.   
    227. > void BN_CTX_start(BN_CTX *ctx)
    228.   {
    229.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_mod.c:192:14: Call
  190.           goto err;
  191.       if (a == b) {
  192.           if (!BN_sqr(t, a, ctx))
                      ^
  193.               goto err;
  194.       } else {

crypto/bn/bn_sqr.c:80:5: Call
    78.       }
    79.   
    80.       BN_CTX_start(ctx);
              ^
    81.       rr = (a != r) ? r : BN_CTX_get(ctx);
    82.       tmp = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:227:1: Parameter `*ctx->stack.indexes`
      225.   }
      226.   
      227. > void BN_CTX_start(BN_CTX *ctx)
      228.   {
      229.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_sqr.c:147:5: Call
    145.       bn_check_top(rr);
    146.       bn_check_top(tmp);
    147.       BN_CTX_end(ctx);
               ^
    148.       return (ret);
    149.   }

crypto/bn/bn_ctx.c:241:1: Parameter `*ctx->stack.indexes`
      239.   }
      240.   
      241. > void BN_CTX_end(BN_CTX *ctx)
      242.   {
      243.       CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:247:27: Call
      245.           ctx->err_stack--;
      246.       else {
      247.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                       ^
      248.           /* Does this stack frame have anything to release? */
      249.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:317:1: <Offset trace>
315.   }
316.   
317. > static unsigned int BN_STACK_pop(BN_STACK *st)
318.   {
319.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:317:1: Parameter `st->depth`
        315.   }
        316.   
        317. > static unsigned int BN_STACK_pop(BN_STACK *st)
        318.   {
        319.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:317:1: <Length trace>
315.   }
316.   
317. > static unsigned int BN_STACK_pop(BN_STACK *st)
318.   {
319.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:317:1: Parameter `*st->indexes`
        315.   }
        316.   
        317. > static unsigned int BN_STACK_pop(BN_STACK *st)
        318.   {
        319.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:319:12: Array access: Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mod_mul` 
        317.   static unsigned int BN_STACK_pop(BN_STACK *st)
        318.   {
        319.       return st->indexes[--(st->depth)];
                          ^
        320.   }
        321.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n    BIGNUM *kinv = NULL, *r = NULL, *s = NULL;\n    BIGNUM *m;\n    BIGNUM *xr;\n    BN_CTX *ctx = NULL;\n    int reason = ERR_R_BN_LIB;\n    DSA_SIG *ret = NULL;\n    int noredo = 0;\n    m = BN_new();\n    xr = BN_new();\n    if (m == NULL || xr == NULL)\n        goto err;\n    if (!dsa->p || !dsa->q || !dsa->g) {\n        reason = DSA_R_MISSING_PARAMETERS;\n        goto err;\n    }\n    s = BN_new();\n    if (s == NULL)\n        goto err;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n redo:\n    if ((dsa->kinv == NULL) || (dsa->r == NULL)) {\n        if (!dsa_sign_setup(dsa, ctx, &kinv, &r, dgst, dlen))\n            goto err;\n    } else {\n        kinv = dsa->kinv;\n        dsa->kinv = NULL;\n        r = dsa->r;\n        dsa->r = NULL;\n        noredo = 1;\n    }\n    if (dlen > BN_num_bytes(dsa->q))\n        dlen = BN_num_bytes(dsa->q);\n    if (BN_bin2bn(dgst, dlen, m) == NULL)\n        goto err;\n    if (!BN_mod_mul(xr, dsa->priv_key, r, dsa->q, ctx))\n        goto err;\n    if (!BN_add(s, xr, m))\n        goto err;\n    if (BN_cmp(s, dsa->q) > 0)\n        if (!BN_sub(s, s, dsa->q))\n            goto err;\n    if (!BN_mod_mul(s, s, kinv, dsa->q, ctx))\n        goto err;\n    if (BN_is_zero(r) || BN_is_zero(s)) {\n        if (noredo) {\n            reason = DSA_R_NEED_NEW_SETUP_VALUES;\n            goto err;\n        }\n        goto redo;\n    }\n    ret = DSA_SIG_new();\n    if (ret == NULL)\n        goto err;\n    ret->r = r;\n    ret->s = s;\n err:\n    if (ret == NULL) {\n        DSAerr(DSA_F_DSA_DO_SIGN, reason);\n        BN_free(r);\n        BN_free(s);\n    }\n    BN_CTX_free(ctx);\n    BN_clear_free(m);\n    BN_clear_free(xr);\n    BN_clear_free(kinv);\n    return (ret);\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n                          BIGNUM **kinvp, BIGNUM **rp,\n                          const unsigned char *dgst, int dlen)\n{\n    BN_CTX *ctx = NULL;\n    BIGNUM *k, *kq, *K, *kinv = NULL, *r = NULL;\n    int ret = 0;\n    if (!dsa->p || !dsa->q || !dsa->g) {\n        DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n        return 0;\n    }\n    k = BN_new();\n    kq = BN_new();\n    if (k == NULL || kq == NULL)\n        goto err;\n    if (ctx_in == NULL) {\n        if ((ctx = BN_CTX_new()) == NULL)\n            goto err;\n    } else\n        ctx = ctx_in;\n    if ((r = BN_new()) == NULL)\n        goto err;\n    do {\n        if (dgst != NULL) {\n            if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n                                       dlen, ctx))\n                goto err;\n        } else if (!BN_rand_range(k, dsa->q))\n            goto err;\n    } while (BN_is_zero(k));\n    if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) {\n        BN_set_flags(k, BN_FLG_CONSTTIME);\n    }\n    if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n        if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n                                    CRYPTO_LOCK_DSA, dsa->p, ctx))\n            goto err;\n    }\n    if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) {\n        if (!BN_copy(kq, k))\n            goto err;\n        if (!BN_add(kq, kq, dsa->q))\n            goto err;\n        if (BN_num_bits(kq) <= BN_num_bits(dsa->q)) {\n            if (!BN_add(kq, kq, dsa->q))\n                goto err;\n        }\n        K = kq;\n    } else {\n        K = k;\n    }\n    DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx,\n                   dsa->method_mont_p);\n    if (!BN_mod(r, r, dsa->q, ctx))\n        goto err;\n    if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n        goto err;\n    BN_clear_free(*kinvp);\n    *kinvp = kinv;\n    kinv = NULL;\n    BN_clear_free(*rp);\n    *rp = r;\n    ret = 1;\n err:\n    if (!ret) {\n        DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n        BN_clear_free(r);\n    }\n    if (ctx != ctx_in)\n        BN_CTX_free(ctx);\n    BN_clear_free(k);\n    BN_clear_free(kq);\n    return (ret);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    BIGNUM *t;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(m);\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (a == b) {\n        if (!BN_sqr(t, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(t, a, b, ctx))\n            goto err;\n    }\n    if (!BN_nnmod(r, t, m, 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_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}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (!rr || !tmp)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n        rr->top = max - 1;\n    else\n        rr->top = max;\n    if (rr != r)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    bn_check_top(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\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}']