crypto/bn/bn_prime.c:208: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_rshift`.
Showing all 11 steps of the trace


crypto/bn/bn_prime.c:188:10: Call
186.       BN_CTX_start(ctx);
187.   
188.       A1 = BN_CTX_get(ctx);
                ^
189.       A1_odd = BN_CTX_get(ctx);
190.       check = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:229:5: Call
  227.       }
  228.       /* OK, make sure the returned bignum is "zero" */
  229.       BN_zero(ret);
             ^
  230.       ctx->used++;
  231.       CTXDBG_RET(ctx, ret);

crypto/bn/bn_lib.c:387:1: Parameter `*a->d`
    385.   }
    386.   
    387. > int BN_set_word(BIGNUM *a, BN_ULONG w)
    388.   {
    389.       bn_check_top(a);

crypto/bn/bn_lib.c:390:9: Call
    388.   {
    389.       bn_check_top(a);
    390.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                   ^
    391.           return 0;
    392.       a->neg = 0;

crypto/bn/bn_lcl.h:651:1: Parameter `*a->d`
      649.                            const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
      650.   
      651. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
      652.   {
      653.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/bn/bn_prime.c:208:10: Call
206.       while (!BN_is_bit_set(A1, k))
207.           k++;
208.       if (!BN_rshift(A1_odd, A1, k))
                ^
209.           goto err;
210.   

crypto/bn/bn_shift.c:122:1: <Length trace>
120.   }
121.   
122. > int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
123.   {
124.       int i, j, nw, lb, rb;

crypto/bn/bn_shift.c:122:1: Parameter `*a->d`
  120.   }
  121.   
  122. > int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
  123.   {
  124.       int i, j, nw, lb, rb;

crypto/bn/bn_shift.c:153:5: Assignment
  151.       }
  152.   
  153.       f = &(a->d[nw]);
             ^
  154.       t = r->d;
  155.       j = a->top - nw;

crypto/bn/bn_shift.c:162:15: Assignment
  160.               *(t++) = *(f++);
  161.       } else {
  162.           l = *(f++);
                       ^
  163.           for (i = j - 1; i != 0; i--) {
  164.               tmp = (l >> rb) & BN_MASK2;

crypto/bn/bn_shift.c:165:17: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_rshift` 
  163.           for (i = j - 1; i != 0; i--) {
  164.               tmp = (l >> rb) & BN_MASK2;
  165.               l = *(f++);
                         ^
  166.               *(t++) = (tmp | (l << lb)) & BN_MASK2;
  167.           }

int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
{
    int i, j, nw, lb, rb;
    BN_ULONG *t, *f;
    BN_ULONG l, tmp;
    bn_check_top(r);
    bn_check_top(a);
    if (n < 0) {
        BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);
        return 0;
    }
    nw = n / BN_BITS2;
    rb = n % BN_BITS2;
    lb = BN_BITS2 - rb;
    if (nw >= a->top || a->top == 0) {
        BN_zero(r);
        return 1;
    }
    i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;
    if (r != a) {
        if (bn_wexpand(r, i) == NULL)
            return 0;
        r->neg = a->neg;
    } else {
        if (n == 0)
            return 1;
    }
    f = &(a->d[nw]);
    t = r->d;
    j = a->top - nw;
    r->top = i;
    if (rb == 0) {
        for (i = j; i != 0; i--)
            *(t++) = *(f++);
    } else {
        l = *(f++);
        for (i = j - 1; i != 0; i--) {
            tmp = (l >> rb) & BN_MASK2;
            l = *(f++);
            *(t++) = (tmp | (l << lb)) & BN_MASK2;
        }
        if ((l = (l >> rb) & BN_MASK2))
            *(t) = l;
    }
    if (!r->top)
        r->neg = 0;
    bn_check_top(r);
    return 1;
}
['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    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 BN_is_word(a, primes[i]);\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    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_priv_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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return 0;\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int i, j, nw, lb, rb;\n    BN_ULONG *t, *f;\n    BN_ULONG l, tmp;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (n < 0) {\n        BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n        return 0;\n    }\n    nw = n / BN_BITS2;\n    rb = n % BN_BITS2;\n    lb = BN_BITS2 - rb;\n    if (nw >= a->top || a->top == 0) {\n        BN_zero(r);\n        return 1;\n    }\n    i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n    if (r != a) {\n        if (bn_wexpand(r, i) == NULL)\n            return 0;\n        r->neg = a->neg;\n    } else {\n        if (n == 0)\n            return 1;\n    }\n    f = &(a->d[nw]);\n    t = r->d;\n    j = a->top - nw;\n    r->top = i;\n    if (rb == 0) {\n        for (i = j; i != 0; i--)\n            *(t++) = *(f++);\n    } else {\n        l = *(f++);\n        for (i = j - 1; i != 0; i--) {\n            tmp = (l >> rb) & BN_MASK2;\n            l = *(f++);\n            *(t++) = (tmp | (l << lb)) & BN_MASK2;\n        }\n        if ((l = (l >> rb) & BN_MASK2))\n            *(t) = l;\n    }\n    if (!r->top)\n        r->neg = 0;\n    bn_check_top(r);\n    return 1;\n}']