crypto/bn/bn_prime.c:224: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `bn_miller_rabin_is_prime`.
Showing all 21 steps of the trace


crypto/bn/bn_prime.c:187:1: Parameter `w->top`
185.   
186.   /* See FIPS 186-4 C.3.1 Miller Rabin Probabilistic Primality Test. */
187. > int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,
188.                               int do_trial_division, BN_GENCB *cb)
189.   {

crypto/bn/bn_prime.c:194:9: Call
192.   
193.       /* w must be bigger than 1 */
194.       if (BN_cmp(w, BN_value_one()) <= 0)
               ^
195.           return 0;
196.   

crypto/bn/bn_lib.c:579:1: Parameter `a->top`
  577.   }
  578.   
  579. > int BN_cmp(const BIGNUM *a, const BIGNUM *b)
  580.   {
  581.       int i;

crypto/bn/bn_prime.c:198:9: Call
196.   
197.       /* w must be odd */
198.       if (BN_is_odd(w)) {
               ^
199.           /* Take care of the really small prime 3 */
200.           if (BN_is_word(w, 3))

crypto/bn/bn_lib.c:879:1: Parameter `a->top`
  877.   }
  878.   
  879. > int BN_is_odd(const BIGNUM *a)
  880.   {
  881.       return (a->top > 0) && (a->d[0] & 1);

crypto/bn/bn_prime.c:200:13: Call
198.       if (BN_is_odd(w)) {
199.           /* Take care of the really small prime 3 */
200.           if (BN_is_word(w, 3))
                   ^
201.               return 1;
202.       } else {

crypto/bn/bn_lib.c:874:1: Parameter `a->top`
  872.   }
  873.   
  874. > int BN_is_word(const BIGNUM *a, const BN_ULONG w)
  875.   {
  876.       return BN_abs_is_word(a, w) && (!w || !a->neg);

crypto/bn/bn_lib.c:876:12: Call
  874.   int BN_is_word(const BIGNUM *a, const BN_ULONG w)
  875.   {
  876.       return BN_abs_is_word(a, w) && (!w || !a->neg);
                    ^
  877.   }
  878.   

crypto/bn/bn_lib.c:859:1: Parameter `a->top`
    857.   }
    858.   
    859. > int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
    860.   {
    861.       return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));

crypto/bn/bn_prime.c:224:11: Call
222.           goto err;
223.   
224.       ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);
                 ^
225.       if (!ret)
226.           goto err;

crypto/bn/bn_prime.c:249:1: Parameter `w->top`
  247.    * returns 0 if there was an error, otherwise it returns 1.
  248.    */
  249. > int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,
  250.                                BN_GENCB *cb, int enhanced, int *status)
  251.   {

crypto/bn/bn_prime.c:257:10: Call
  255.   
  256.       /* w must be odd */
  257.       if (!BN_is_odd(w))
                  ^
  258.           return 0;
  259.   

crypto/bn/bn_lib.c:879:1: Parameter `a->top`
    877.   }
    878.   
    879. > int BN_is_odd(const BIGNUM *a)
    880.   {
    881.       return (a->top > 0) && (a->d[0] & 1);

crypto/bn/bn_prime.c:271:16: Call
  269.       if (!(b != NULL
  270.               /* w1 := w - 1 */
  271.               && BN_copy(w1, w)
                        ^
  272.               && BN_sub_word(w1, 1)
  273.               /* w3 := w - 3 */

crypto/bn/bn_lib.c:281:1: <Offset trace>
279.   }
280.   
281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
282.   {
283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: Parameter `b->top`
    279.   }
    280.   
    281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    282.   {
    283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: <Length trace>
279.   }
280.   
281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
282.   {
283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: Parameter `*a->d`
    279.   }
    280.   
    281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    282.   {
    283.       bn_check_top(b);

crypto/bn/bn_lib.c:287:9: Call
    285.       if (a == b)
    286.           return a;
    287.       if (bn_wexpand(a, b->top) == NULL)
                   ^
    288.           return NULL;
    289.   

crypto/bn/bn_lib.c:960:1: Parameter `*a->d`
      958.   }
      959.   
      960. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
      961.   {
      962.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:291:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `bn_miller_rabin_is_prime` 
    289.   
    290.       if (b->top > 0)
    291.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                   ^
    292.   
    293.       a->neg = b->neg;

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    a->neg = b->neg;
    a->top = b->top;
    a->flags |= b->flags & BN_FLG_FIXED_TOP;
    bn_check_top(a);
    return a;
}
['int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,\n                            int do_trial_division, BN_GENCB *cb)\n{\n    int i, status, ret = -1;\n    BN_CTX *ctx = NULL;\n    if (BN_cmp(w, BN_value_one()) <= 0)\n        return 0;\n    if (BN_is_odd(w)) {\n        if (BN_is_word(w, 3))\n            return 1;\n    } else {\n        return BN_is_word(w, 2);\n    }\n    if (do_trial_division) {\n        for (i = 1; i < NUMPRIMES; i++) {\n            BN_ULONG mod = BN_mod_word(w, primes[i]);\n            if (mod == (BN_ULONG)-1)\n                return -1;\n            if (mod == 0)\n                return BN_is_word(w, primes[i]);\n        }\n        if (!BN_GENCB_call(cb, 1, -1))\n            return -1;\n    }\n    if (ctx_passed != NULL)\n        ctx = ctx_passed;\n    else if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);\n    if (!ret)\n        goto err;\n    ret = (status == BN_PRIMETEST_PROBABLY_PRIME);\nerr:\n    if (ctx_passed == NULL)\n        BN_CTX_free(ctx);\n    return ret;\n}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n{\n    int i;\n    int gt, lt;\n    BN_ULONG t1, t2;\n    if ((a == NULL) || (b == NULL)) {\n        if (a != NULL)\n            return -1;\n        else if (b != NULL)\n            return 1;\n        else\n            return 0;\n    }\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->neg != b->neg) {\n        if (a->neg)\n            return -1;\n        else\n            return 1;\n    }\n    if (a->neg == 0) {\n        gt = 1;\n        lt = -1;\n    } else {\n        gt = -1;\n        lt = 1;\n    }\n    if (a->top > b->top)\n        return gt;\n    if (a->top < b->top)\n        return lt;\n    for (i = a->top - 1; i >= 0; i--) {\n        t1 = a->d[i];\n        t2 = b->d[i];\n        if (t1 > t2)\n            return gt;\n        if (t1 < t2)\n            return lt;\n    }\n    return 0;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n    return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n    return BN_abs_is_word(a, w) && (!w || !a->neg);\n}', 'int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n    return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));\n}', 'int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,\n                             BN_GENCB *cb, int enhanced, int *status)\n{\n    int i, j, a, ret = 0;\n    BIGNUM *g, *w1, *w3, *x, *m, *z, *b;\n    BN_MONT_CTX *mont = NULL;\n    if (!BN_is_odd(w))\n        return 0;\n    BN_CTX_start(ctx);\n    g = BN_CTX_get(ctx);\n    w1 = BN_CTX_get(ctx);\n    w3 = BN_CTX_get(ctx);\n    x = BN_CTX_get(ctx);\n    m = BN_CTX_get(ctx);\n    z = BN_CTX_get(ctx);\n    b = BN_CTX_get(ctx);\n    if (!(b != NULL\n            && BN_copy(w1, w)\n            && BN_sub_word(w1, 1)\n            && BN_copy(w3, w)\n            && BN_sub_word(w3, 3)))\n        goto err;\n    if (BN_is_zero(w3) || BN_is_negative(w3))\n        goto err;\n    a = 1;\n    while (!BN_is_bit_set(w1, a))\n        a++;\n    if (!BN_rshift(m, w1, a))\n        goto err;\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))\n        goto err;\n    if (iterations == BN_prime_checks)\n        iterations = BN_prime_checks_for_size(BN_num_bits(w));\n    for (i = 0; i < iterations; ++i) {\n        if (!BN_priv_rand_range(b, w3) || !BN_add_word(b, 2))\n            goto err;\n        if (enhanced) {\n            if (!BN_gcd(g, b, w, ctx))\n                goto err;\n            if (!BN_is_one(g)) {\n                *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n                ret = 1;\n                goto err;\n            }\n        }\n        if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))\n            goto err;\n        if (BN_is_one(z) || BN_cmp(z, w1) == 0)\n            goto outer_loop;\n        for (j = 1; j < a ; ++j) {\n            if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n                goto err;\n            if (BN_cmp(z, w1) == 0)\n                goto outer_loop;\n            if (BN_is_one(z))\n                goto composite;\n        }\n        if (!BN_GENCB_call(cb, 1, i))\n            goto err;\n        if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n            goto err;\n        if (BN_is_one(z))\n            goto composite;\n        if (!BN_copy(x, z))\n            goto err;\ncomposite:\n        if (enhanced) {\n            if (!BN_sub_word(x, 1) || !BN_gcd(g, x, w, ctx))\n                goto err;\n            if (BN_is_one(g))\n                *status = BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME;\n            else\n                *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n        } else {\n            *status = BN_PRIMETEST_COMPOSITE;\n        }\n        ret = 1;\n        goto err;\nouter_loop: ;\n    }\n    *status = BN_PRIMETEST_PROBABLY_PRIME;\n    ret = 1;\nerr:\n    BN_clear(g);\n    BN_clear(w1);\n    BN_clear(w3);\n    BN_clear(x);\n    BN_clear(m);\n    BN_clear(z);\n    BN_clear(b);\n    BN_CTX_end(ctx);\n    BN_MONT_CTX_free(mont);\n    return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->neg = b->neg;\n    a->top = b->top;\n    a->flags |= b->flags & BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']