crypto/rsa/rsa_chk.c:98: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mod_mul`.
Showing all 25 steps of the trace


crypto/rsa/rsa_chk.c:54:9: Call
52.   
53.       /* p prime? */
54.       if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {
              ^
55.           ret = 0;
56.           RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);

crypto/bn/bn_prime.c:194:1: Parameter `ctx_passed->stack.depth`
  192.   }
  193.   
  194. > int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
  195.                      BN_GENCB *cb)
  196.   {

crypto/bn/bn_prime.c:197:12: Call
  195.                      BN_GENCB *cb)
  196.   {
  197.       return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);
                    ^
  198.   }
  199.   

crypto/bn/bn_prime.c:200:1: Parameter `ctx_passed->stack.depth`
    198.   }
    199.   
    200. > int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
    201.                               int do_trial_division, BN_GENCB *cb)
    202.   {

crypto/rsa/rsa_chk.c:60:9: Call
58.   
59.       /* q prime? */
60.       if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {
              ^
61.           ret = 0;
62.           RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);

crypto/bn/bn_prime.c:194:1: Parameter `ctx_passed->stack.depth`
  192.   }
  193.   
  194. > int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
  195.                      BN_GENCB *cb)
  196.   {

crypto/bn/bn_prime.c:197:12: Call
  195.                      BN_GENCB *cb)
  196.   {
  197.       return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);
                    ^
  198.   }
  199.   

crypto/bn/bn_prime.c:200:1: Parameter `ctx_passed->stack.depth`
    198.   }
    199.   
    200. > int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
    201.                               int do_trial_division, BN_GENCB *cb)
    202.   {

crypto/rsa/rsa_chk.c:66:10: Call
64.   
65.       /* n = p*q? */
66.       if (!BN_mul(i, key->p, key->q, ctx)) {
               ^
67.           ret = -1;
68.           goto err;

crypto/bn/bn_mul.c:829:1: Parameter `ctx->stack.depth`
  827.   #endif                          /* BN_RECURSION */
  828.   
  829. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  830.   {
  831.       int ret = 0;

crypto/rsa/rsa_chk.c:98:10: Call
96.           goto err;
97.       }
98.       if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {
                ^
99.           ret = -1;
100.           goto err;

crypto/bn/bn_mod.c:73:1: Parameter `ctx->stack.depth`
  71.   
  72.   /* slow but works */
  73. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  74.                  BN_CTX *ctx)
  75.   {

crypto/bn/bn_mod.c:83:5: Call
  81.       bn_check_top(m);
  82.   
  83.       BN_CTX_start(ctx);
            ^
  84.       if ((t = BN_CTX_get(ctx)) == NULL)
  85.           goto err;

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_mod.c:90:14: Call
  88.               goto err;
  89.       } else {
  90.           if (!BN_mul(t, a, b, ctx))
                     ^
  91.               goto err;
  92.       }

crypto/bn/bn_mul.c:855:5: Call
    853.       top = al + bl;
    854.   
    855.       BN_CTX_start(ctx);
               ^
    856.       if ((r == a) || (r == b)) {
    857.           if ((rr = BN_CTX_get(ctx)) == NULL)

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_mul.c:979:5: Call
    977.    err:
    978.       bn_check_top(r);
    979.       BN_CTX_end(ctx);
               ^
    980.       return (ret);
    981.   }

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_mod_mul` 
        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 RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n    BIGNUM *i, *j, *k, *l, *m;\n    BN_CTX *ctx;\n    int ret = 1;\n    if (key->p == NULL || key->q == NULL || key->n == NULL\n            || key->e == NULL || key->d == NULL) {\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n        return 0;\n    }\n    i = BN_new();\n    j = BN_new();\n    k = BN_new();\n    l = BN_new();\n    m = BN_new();\n    ctx = BN_CTX_new();\n    if (i == NULL || j == NULL || k == NULL || l == NULL\n            || m == NULL || ctx == NULL) {\n        ret = -1;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (BN_is_one(key->e)) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n    }\n    if (!BN_is_odd(key->e)) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n    }\n    if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n    }\n    if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n    }\n    if (!BN_mul(i, key->p, key->q, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (BN_cmp(i, key->n) != 0) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n    }\n    if (!BN_sub(i, key->p, BN_value_one())) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_sub(j, key->q, BN_value_one())) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_mul(l, i, j, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_gcd(m, i, j, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_div(k, NULL, l, m, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_is_one(i)) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n    }\n    if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n        if (!BN_sub(i, key->p, BN_value_one())) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_mod(j, key->d, i, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(j, key->dmp1) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n        }\n        if (!BN_sub(i, key->q, BN_value_one())) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_mod(j, key->d, i, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(j, key->dmq1) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n        }\n        if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(i, key->iqmp) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n        }\n    }\n err:\n    BN_free(i);\n    BN_free(j);\n    BN_free(k);\n    BN_free(l);\n    BN_free(m);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n                   BN_GENCB *cb)\n{\n    return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n                            int do_trial_division, BN_GENCB *cb)\n{\n    int i, j, ret = -1;\n    int k;\n    BN_CTX *ctx = NULL;\n    BIGNUM *A1, *A1_odd, *check;\n    BN_MONT_CTX *mont = NULL;\n    const BIGNUM *A = NULL;\n    if (BN_cmp(a, BN_value_one()) <= 0)\n        return 0;\n    if (checks == BN_prime_checks)\n        checks = BN_prime_checks_for_size(BN_num_bits(a));\n    if (!BN_is_odd(a))\n        return BN_is_word(a, 2);\n    if (do_trial_division) {\n        for (i = 1; i < NUMPRIMES; i++) {\n            BN_ULONG mod = BN_mod_word(a, primes[i]);\n            if (mod == (BN_ULONG)-1)\n                goto err;\n            if (mod == 0)\n                return 0;\n        }\n        if (!BN_GENCB_call(cb, 1, -1))\n            goto err;\n    }\n    if (ctx_passed != NULL)\n        ctx = ctx_passed;\n    else if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    if (a->neg) {\n        BIGNUM *t;\n        if ((t = BN_CTX_get(ctx)) == NULL)\n            goto err;\n        BN_copy(t, a);\n        t->neg = 0;\n        A = t;\n    } else\n        A = a;\n    A1 = BN_CTX_get(ctx);\n    A1_odd = BN_CTX_get(ctx);\n    check = BN_CTX_get(ctx);\n    if (check == NULL)\n        goto err;\n    if (!BN_copy(A1, A))\n        goto err;\n    if (!BN_sub_word(A1, 1))\n        goto err;\n    if (BN_is_zero(A1)) {\n        ret = 0;\n        goto err;\n    }\n    k = 1;\n    while (!BN_is_bit_set(A1, k))\n        k++;\n    if (!BN_rshift(A1_odd, A1, k))\n        goto err;\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL)\n        goto err;\n    if (!BN_MONT_CTX_set(mont, A, ctx))\n        goto err;\n    for (i = 0; i < checks; i++) {\n        if (!BN_pseudo_rand_range(check, A1))\n            goto err;\n        if (!BN_add_word(check, 1))\n            goto err;\n        j = witness(check, A, A1, A1_odd, k, ctx, mont);\n        if (j == -1)\n            goto err;\n        if (j) {\n            ret = 0;\n            goto err;\n        }\n        if (!BN_GENCB_call(cb, 1, i))\n            goto err;\n    }\n    ret = 1;\n err:\n    if (ctx != NULL) {\n        BN_CTX_end(ctx);\n        if (ctx_passed == NULL)\n            BN_CTX_free(ctx);\n    }\n    BN_MONT_CTX_free(mont);\n    return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = 0;\n    int top, al, bl;\n    BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    int i;\n#endif\n#ifdef BN_RECURSION\n    BIGNUM *t = NULL;\n    int j = 0, k;\n#endif\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(r);\n    al = a->top;\n    bl = b->top;\n    if ((al == 0) || (bl == 0)) {\n        BN_zero(r);\n        return (1);\n    }\n    top = al + bl;\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == b)) {\n        if ((rr = BN_CTX_get(ctx)) == NULL)\n            goto err;\n    } else\n        rr = r;\n    rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n    if (i == 0) {\n# if 0\n        if (al == 4) {\n            if (bn_wexpand(rr, 8) == NULL)\n                goto err;\n            rr->top = 8;\n            bn_mul_comba4(rr->d, a->d, b->d);\n            goto end;\n        }\n# endif\n        if (al == 8) {\n            if (bn_wexpand(rr, 16) == NULL)\n                goto err;\n            rr->top = 16;\n            bn_mul_comba8(rr->d, a->d, b->d);\n            goto end;\n        }\n    }\n#endif\n#ifdef BN_RECURSION\n    if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n        if (i >= -1 && i <= 1) {\n            if (i >= 0) {\n                j = BN_num_bits_word((BN_ULONG)al);\n            }\n            if (i == -1) {\n                j = BN_num_bits_word((BN_ULONG)bl);\n            }\n            j = 1 << (j - 1);\n            assert(j <= al || j <= bl);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (t == NULL)\n                goto err;\n            if (al > j || bl > j) {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d,\n                                      j, al - j, bl - j, t->d);\n            } else {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n# if 0\n        if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n            BIGNUM *tmp_bn = (BIGNUM *)b;\n            if (bn_wexpand(tmp_bn, al) == NULL)\n                goto err;\n            tmp_bn->d[bl] = 0;\n            bl++;\n            i--;\n        } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n            BIGNUM *tmp_bn = (BIGNUM *)a;\n            if (bn_wexpand(tmp_bn, bl) == NULL)\n                goto err;\n            tmp_bn->d[al] = 0;\n            al++;\n            i++;\n        }\n        if (i == 0) {\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (al == j) {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n            } else {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n# endif\n    }\n#endif\n    if (bn_wexpand(rr, top) == NULL)\n        goto err;\n    rr->top = top;\n    bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n    bn_correct_top(rr);\n    if (r != rr)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    bn_check_top(r);\n    BN_CTX_end(ctx);\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}', '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}']