crypto/bn/bn_exp2.c:83: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_to_montgomery`.
Showing all 20 steps of the trace


crypto/bn/bn_exp2.c:16:1: Parameter `ctx->stack.depth`
14.   #define TABLE_SIZE      32
15.   
16. > int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
17.                        const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
18.                        BN_CTX *ctx, BN_MONT_CTX *in_mont)

crypto/bn/bn_exp2.c:48:5: Call
46.       bits = (bits1 > bits2) ? bits1 : bits2;
47.   
48.       BN_CTX_start(ctx);
          ^
49.       d = BN_CTX_get(ctx);
50.       r = 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_exp2.c:83:10: Call
81.       }
82.   
83.       if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))
               ^
84.           goto err;
85.       if (window1 > 1) {

crypto/bn/bn_lib.c:943:1: Parameter `ctx->stack.depth`
  941.   }
  942.   
  943. > int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
  944.                        BN_CTX *ctx)
  945.   {

crypto/bn/bn_lib.c:946:12: Call
  944.                        BN_CTX *ctx)
  945.   {
  946.       return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);
                    ^
  947.   }
  948.   

crypto/bn/bn_mont.c:26:1: Parameter `ctx->stack.depth`
    24.   #endif
    25.   
    26. > int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
    27.                             BN_MONT_CTX *mont, BN_CTX *ctx)
    28.   {

crypto/bn/bn_mont.c:46:5: Call
    44.   #endif
    45.   
    46.       BN_CTX_start(ctx);
              ^
    47.       tmp = BN_CTX_get(ctx);
    48.       if (tmp == NULL)

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_mont.c:53:14: Call
    51.       bn_check_top(tmp);
    52.       if (a == b) {
    53.           if (!BN_sqr(tmp, a, ctx))
                       ^
    54.               goto err;
    55.       } else {

crypto/bn/bn_sqr.c:32:5: Call
      30.       }
      31.   
      32.       BN_CTX_start(ctx);
                ^
      33.       rr = (a != r) ? r : BN_CTX_get(ctx);
      34.       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_sqr.c:99:5: Call
      97.       bn_check_top(rr);
      98.       bn_check_top(tmp);
      99.       BN_CTX_end(ctx);
                 ^
      100.       return (ret);
      101.   }

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

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

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

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

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

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n                     const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n                     BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n    int i, j, bits, b, bits1, bits2, ret =\n        0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n    int r_is_one = 1;\n    BIGNUM *d, *r;\n    const BIGNUM *a_mod_m;\n    BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n    BN_MONT_CTX *mont = NULL;\n    bn_check_top(a1);\n    bn_check_top(p1);\n    bn_check_top(a2);\n    bn_check_top(p2);\n    bn_check_top(m);\n    if (!(m->d[0] & 1)) {\n        BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n        return (0);\n    }\n    bits1 = BN_num_bits(p1);\n    bits2 = BN_num_bits(p2);\n    if ((bits1 == 0) && (bits2 == 0)) {\n        ret = BN_one(rr);\n        return ret;\n    }\n    bits = (bits1 > bits2) ? bits1 : bits2;\n    BN_CTX_start(ctx);\n    d = BN_CTX_get(ctx);\n    r = BN_CTX_get(ctx);\n    val1[0] = BN_CTX_get(ctx);\n    val2[0] = BN_CTX_get(ctx);\n    if (!d || !r || !val1[0] || !val2[0])\n        goto err;\n    if (in_mont != NULL)\n        mont = in_mont;\n    else {\n        if ((mont = BN_MONT_CTX_new()) == NULL)\n            goto err;\n        if (!BN_MONT_CTX_set(mont, m, ctx))\n            goto err;\n    }\n    window1 = BN_window_bits_for_exponent_size(bits1);\n    window2 = BN_window_bits_for_exponent_size(bits2);\n    if (a1->neg || BN_ucmp(a1, m) >= 0) {\n        if (!BN_mod(val1[0], a1, m, ctx))\n            goto err;\n        a_mod_m = val1[0];\n    } else\n        a_mod_m = a1;\n    if (BN_is_zero(a_mod_m)) {\n        BN_zero(rr);\n        ret = 1;\n        goto err;\n    }\n    if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n        goto err;\n    if (window1 > 1) {\n        if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n            goto err;\n        j = 1 << (window1 - 1);\n        for (i = 1; i < j; i++) {\n            if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n                !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n                goto err;\n        }\n    }\n    if (a2->neg || BN_ucmp(a2, m) >= 0) {\n        if (!BN_mod(val2[0], a2, m, ctx))\n            goto err;\n        a_mod_m = val2[0];\n    } else\n        a_mod_m = a2;\n    if (BN_is_zero(a_mod_m)) {\n        BN_zero(rr);\n        ret = 1;\n        goto err;\n    }\n    if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n        goto err;\n    if (window2 > 1) {\n        if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n            goto err;\n        j = 1 << (window2 - 1);\n        for (i = 1; i < j; i++) {\n            if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n                !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n                goto err;\n        }\n    }\n    r_is_one = 1;\n    wvalue1 = 0;\n    wvalue2 = 0;\n    wpos1 = 0;\n    wpos2 = 0;\n    if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n        goto err;\n    for (b = bits - 1; b >= 0; b--) {\n        if (!r_is_one) {\n            if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n                goto err;\n        }\n        if (!wvalue1)\n            if (BN_is_bit_set(p1, b)) {\n                i = b - window1 + 1;\n                while (!BN_is_bit_set(p1, i))\n                    i++;\n                wpos1 = i;\n                wvalue1 = 1;\n                for (i = b - 1; i >= wpos1; i--) {\n                    wvalue1 <<= 1;\n                    if (BN_is_bit_set(p1, i))\n                        wvalue1++;\n                }\n            }\n        if (!wvalue2)\n            if (BN_is_bit_set(p2, b)) {\n                i = b - window2 + 1;\n                while (!BN_is_bit_set(p2, i))\n                    i++;\n                wpos2 = i;\n                wvalue2 = 1;\n                for (i = b - 1; i >= wpos2; i--) {\n                    wvalue2 <<= 1;\n                    if (BN_is_bit_set(p2, i))\n                        wvalue2++;\n                }\n            }\n        if (wvalue1 && b == wpos1) {\n            if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n                goto err;\n            wvalue1 = 0;\n            r_is_one = 0;\n        }\n        if (wvalue2 && b == wpos2) {\n            if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n                goto err;\n            wvalue2 = 0;\n            r_is_one = 0;\n        }\n    }\n    if (!BN_from_montgomery(rr, r, mont, ctx))\n        goto err;\n    ret = 1;\n err:\n    if (in_mont == NULL)\n        BN_MONT_CTX_free(mont);\n    BN_CTX_end(ctx);\n    bn_check_top(rr);\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_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n                     BN_CTX *ctx)\n{\n    return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                          BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n    BIGNUM *tmp;\n    int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n    int num = mont->N.top;\n    if (num > 1 && a->top == num && b->top == num) {\n        if (bn_wexpand(r, num) == NULL)\n            return (0);\n        if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n            r->neg = a->neg ^ b->neg;\n            r->top = num;\n            bn_correct_top(r);\n            return (1);\n        }\n    }\n#endif\n    BN_CTX_start(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (tmp == NULL)\n        goto err;\n    bn_check_top(tmp);\n    if (a == b) {\n        if (!BN_sqr(tmp, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(tmp, a, b, ctx))\n            goto err;\n    }\n#ifdef MONT_WORD\n    if (!BN_from_montgomery_word(r, tmp, mont))\n        goto err;\n#else\n    if (!BN_from_montgomery(r, tmp, mont, ctx))\n        goto err;\n#endif\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return (ret);\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}']