crypto/bn/bn_gcd.c:609: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_nnmod`.
Showing all 18 steps of the trace


crypto/bn/bn_gcd.c:458:1: Parameter `ctx->stack.depth`
456.    * not contain branches that may leak sensitive information.
457.    */
458. > static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,
459.                                           const BIGNUM *a, const BIGNUM *n,
460.                                           BN_CTX *ctx)

crypto/bn/bn_gcd.c:469:5: Call
467.       bn_check_top(n);
468.   
469.       BN_CTX_start(ctx);
           ^
470.       A = BN_CTX_get(ctx);
471.       B = BN_CTX_get(ctx);

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

crypto/bn/bn_gcd.c:609:18: Call
607.                   goto err;
608.           } else {
609.               if (!BN_nnmod(R, Y, n, ctx))
                        ^
610.                   goto err;
611.           }

crypto/bn/bn_mod.c:13:1: Parameter `ctx->stack.depth`
  11.   #include "bn_lcl.h"
  12.   
  13. > int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
  14.   {
  15.       /*

crypto/bn/bn_mod.c:20:11: Call
  18.        */
  19.   
  20.       if (!(BN_mod(r, m, d, ctx)))
                  ^
  21.           return 0;
  22.       if (!r->neg)

crypto/bn/bn_div.c:209:1: Parameter `ctx->stack.depth`
    207.    * If 'dv' or 'rm' is NULL, the respective value is not returned.
    208.    */
    209. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    210.              BN_CTX *ctx)
    211.   {

crypto/bn/bn_div.c:229:11: Call
    227.       }
    228.   
    229.       ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);
                     ^
    230.   
    231.       if (ret) {

crypto/bn/bn_div.c:280:5: Call
      278.       bn_check_top(rm);
      279.   
      280.       BN_CTX_start(ctx);
                 ^
      281.       res = (dv == NULL) ? BN_CTX_get(ctx) : dv;
      282.       tmp = BN_CTX_get(ctx);

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_div.c:450:5: Call
      448.       if (rm != NULL)
      449.           bn_rshift_fixed_top(rm, snum, norm_shift);
      450.       BN_CTX_end(ctx);
                 ^
      451.       return 1;
      452.    err:

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:274:1: <Offset trace>
272.   }
273.   
274. > static unsigned int BN_STACK_pop(BN_STACK *st)
275.   {
276.       return st->indexes[--(st->depth)];

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

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

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

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

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n                                        const BIGNUM *a, const BIGNUM *n,\n                                        BN_CTX *ctx)\n{\n    BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n    BIGNUM *ret = NULL;\n    int sign;\n    bn_check_top(a);\n    bn_check_top(n);\n    BN_CTX_start(ctx);\n    A = BN_CTX_get(ctx);\n    B = BN_CTX_get(ctx);\n    X = BN_CTX_get(ctx);\n    D = BN_CTX_get(ctx);\n    M = BN_CTX_get(ctx);\n    Y = BN_CTX_get(ctx);\n    T = BN_CTX_get(ctx);\n    if (T == NULL)\n        goto err;\n    if (in == NULL)\n        R = BN_new();\n    else\n        R = in;\n    if (R == NULL)\n        goto err;\n    BN_one(X);\n    BN_zero(Y);\n    if (BN_copy(B, a) == NULL)\n        goto err;\n    if (BN_copy(A, n) == NULL)\n        goto err;\n    A->neg = 0;\n    if (B->neg || (BN_ucmp(B, A) >= 0)) {\n         {\n            BIGNUM local_B;\n            bn_init(&local_B);\n            BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n            if (!BN_nnmod(B, &local_B, A, ctx))\n                goto err;\n        }\n    }\n    sign = -1;\n    while (!BN_is_zero(B)) {\n        BIGNUM *tmp;\n        {\n            BIGNUM local_A;\n            bn_init(&local_A);\n            BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n            if (!BN_div(D, M, &local_A, B, ctx))\n                goto err;\n        }\n        tmp = A;\n        A = B;\n        B = M;\n        if (!BN_mul(tmp, D, X, ctx))\n            goto err;\n        if (!BN_add(tmp, tmp, Y))\n            goto err;\n        M = Y;\n        Y = X;\n        X = tmp;\n        sign = -sign;\n    }\n    if (sign < 0) {\n        if (!BN_sub(Y, n, Y))\n            goto err;\n    }\n    if (BN_is_one(A)) {\n        if (!Y->neg && BN_ucmp(Y, n) < 0) {\n            if (!BN_copy(R, Y))\n                goto err;\n        } else {\n            if (!BN_nnmod(R, Y, n, ctx))\n                goto err;\n        }\n    } else {\n        BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n        goto err;\n    }\n    ret = R;\n err:\n    if ((ret == NULL) && (in == NULL))\n        BN_free(R);\n    BN_CTX_end(ctx);\n    bn_check_top(ret);\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_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n    if (!(BN_mod(r, m, d, ctx)))\n        return 0;\n    if (!r->neg)\n        return 1;\n    return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n           BN_CTX *ctx)\n{\n    int ret;\n    if (BN_is_zero(divisor)) {\n        BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n        return 0;\n    }\n    if (divisor->d[divisor->top - 1] == 0) {\n        BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n        return 0;\n    }\n    ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n    if (ret) {\n        if (dv != NULL)\n            bn_correct_top(dv);\n        if (rm != NULL)\n            bn_correct_top(rm);\n    }\n    return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n                     const BIGNUM *divisor, BN_CTX *ctx)\n{\n    int norm_shift, i, j, loop;\n    BIGNUM *tmp, *snum, *sdiv, *res;\n    BN_ULONG *resp, *wnum, *wnumtop;\n    BN_ULONG d0, d1;\n    int num_n, div_n;\n    assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n    bn_check_top(num);\n    bn_check_top(divisor);\n    bn_check_top(dv);\n    bn_check_top(rm);\n    BN_CTX_start(ctx);\n    res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n    tmp = BN_CTX_get(ctx);\n    snum = BN_CTX_get(ctx);\n    sdiv = BN_CTX_get(ctx);\n    if (sdiv == NULL)\n        goto err;\n    if (!BN_copy(sdiv, divisor))\n        goto err;\n    norm_shift = bn_left_align(sdiv);\n    sdiv->neg = 0;\n    if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n        goto err;\n    div_n = sdiv->top;\n    num_n = snum->top;\n    if (num_n <= div_n) {\n        if (bn_wexpand(snum, div_n + 1) == NULL)\n            goto err;\n        memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n        snum->top = num_n = div_n + 1;\n    }\n    loop = num_n - div_n;\n    wnum = &(snum->d[loop]);\n    wnumtop = &(snum->d[num_n - 1]);\n    d0 = sdiv->d[div_n - 1];\n    d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n    if (!bn_wexpand(res, loop))\n        goto err;\n    res->neg = (num->neg ^ divisor->neg);\n    res->top = loop;\n    res->flags |= BN_FLG_FIXED_TOP;\n    resp = &(res->d[loop]);\n    if (!bn_wexpand(tmp, (div_n + 1)))\n        goto err;\n    for (i = 0; i < loop; i++, wnumtop--) {\n        BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n        q = bn_div_3_words(wnumtop, d1, d0);\n# else\n        BN_ULONG n0, n1, rem = 0;\n        n0 = wnumtop[0];\n        n1 = wnumtop[-1];\n        if (n0 == d0)\n            q = BN_MASK2;\n        else {\n            BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n#  ifdef BN_LLONG\n            BN_ULLONG t2;\n#   if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n            q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n#   else\n            q = bn_div_words(n0, n1, d0);\n#   endif\n#   ifndef REMAINDER_IS_ALREADY_CALCULATED\n            rem = (n1 - q * d0) & BN_MASK2;\n#   endif\n            t2 = (BN_ULLONG) d1 *q;\n            for (;;) {\n                if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n                    break;\n                q--;\n                rem += d0;\n                if (rem < d0)\n                    break;\n                t2 -= d1;\n            }\n#  else\n            BN_ULONG t2l, t2h;\n            q = bn_div_words(n0, n1, d0);\n#   ifndef REMAINDER_IS_ALREADY_CALCULATED\n            rem = (n1 - q * d0) & BN_MASK2;\n#   endif\n#   if defined(BN_UMULT_LOHI)\n            BN_UMULT_LOHI(t2l, t2h, d1, q);\n#   elif defined(BN_UMULT_HIGH)\n            t2l = d1 * q;\n            t2h = BN_UMULT_HIGH(d1, q);\n#   else\n            {\n                BN_ULONG ql, qh;\n                t2l = LBITS(d1);\n                t2h = HBITS(d1);\n                ql = LBITS(q);\n                qh = HBITS(q);\n                mul64(t2l, t2h, ql, qh);\n            }\n#   endif\n            for (;;) {\n                if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n                    break;\n                q--;\n                rem += d0;\n                if (rem < d0)\n                    break;\n                if (t2l < d1)\n                    t2h--;\n                t2l -= d1;\n            }\n#  endif\n        }\n# endif\n        l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n        tmp->d[div_n] = l0;\n        wnum--;\n        l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n        q -= l0;\n        for (l0 = 0 - l0, j = 0; j < div_n; j++)\n            tmp->d[j] = sdiv->d[j] & l0;\n        l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n        (*wnumtop) += l0;\n        assert((*wnumtop) == 0);\n        *--resp = q;\n    }\n    snum->neg = num->neg;\n    snum->top = div_n;\n    snum->flags |= BN_FLG_FIXED_TOP;\n    if (rm != NULL)\n        bn_rshift_fixed_top(rm, snum, norm_shift);\n    BN_CTX_end(ctx);\n    return 1;\n err:\n    bn_check_top(rm);\n    BN_CTX_end(ctx);\n    return 0;\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}']