test/bntest.c:2038: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_rshift1`.
Showing all 10 steps of the trace


test/bntest.c:2035:5: Call
2033.       c = BN_new();
2034.   
2035.       BN_bntest_rand(a, 200, 0, 0);
            ^
2036.       a->neg = rand_neg();
2037.       for (i = 0; i < num0; i++) {

crypto/bn/bn_rand.c:210:1: Parameter `*rnd->d`
  208.   }
  209.   
  210. > int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  211.   {
  212.       return bnrand(2, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:212:12: Call
  210.   int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  211.   {
  212.       return bnrand(2, rnd, bits, top, bottom);
                    ^
  213.   }
  214.   

crypto/bn/bn_rand.c:119:1: Parameter `*rnd->d`
    117.   #include <openssl/sha.h>
    118.   
    119. > static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
    120.   {
    121.       unsigned char *buf = NULL;

test/bntest.c:2038:9: Call
2036.       a->neg = rand_neg();
2037.       for (i = 0; i < num0; i++) {
2038.           BN_rshift1(b, a);
                ^
2039.           if (bp != NULL) {
2040.               if (!results) {

crypto/bn/bn_shift.c:95:1: Parameter `*r->d`
  93.   }
  94.   
  95. > int BN_rshift1(BIGNUM *r, const BIGNUM *a)
  96.   {
  97.       BN_ULONG *ap, *rp, t, c;

crypto/bn/bn_shift.c:104:9: Call
  102.   
  103.       if (BN_is_zero(a)) {
  104.           BN_zero(r);
                 ^
  105.           return (1);
  106.       }

crypto/bn/bn_lib.c:530:1: <Length trace>
528.   }
529.   
530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
531.   {
532.       bn_check_top(a);

crypto/bn/bn_lib.c:530:1: Parameter `*a->d`
    528.   }
    529.   
    530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
    531.   {
    532.       bn_check_top(a);

crypto/bn/bn_lib.c:536:5: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_rshift1` 
    534.           return (0);
    535.       a->neg = 0;
    536.       a->d[0] = w;
               ^
    537.       a->top = (w ? 1 : 0);
    538.       bn_check_top(a);

int BN_set_word(BIGNUM *a, BN_ULONG w)
{
    bn_check_top(a);
    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
        return (0);
    a->neg = 0;
    a->d[0] = w;
    a->top = (w ? 1 : 0);
    bn_check_top(a);
    return (1);
}
['int test_rshift1(BIO *bp)\n{\n    BIGNUM *a, *b, *c;\n    int i;\n    a = BN_new();\n    b = BN_new();\n    c = BN_new();\n    BN_bntest_rand(a, 200, 0, 0);\n    a->neg = rand_neg();\n    for (i = 0; i < num0; i++) {\n        BN_rshift1(b, a);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " / 2");\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, b);\n            BIO_puts(bp, "\\n");\n        }\n        BN_sub(c, a, b);\n        BN_sub(c, c, b);\n        if (!BN_is_zero(c) && !BN_abs_is_word(c, 1)) {\n            fprintf(stderr, "Right shift one test failed!\\n");\n            return 0;\n        }\n        BN_copy(a, b);\n    }\n    BN_free(a);\n    BN_free(b);\n    BN_free(c);\n    return (1);\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n    return bnrand(2, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n    unsigned char *buf = NULL;\n    int ret = 0, bit, bytes, mask;\n    time_t tim;\n    if (bits < 0 || (bits == 1 && top > 0)) {\n        BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n        return 0;\n    }\n    if (bits == 0) {\n        BN_zero(rnd);\n        return 1;\n    }\n    bytes = (bits + 7) / 8;\n    bit = (bits - 1) % 8;\n    mask = 0xff << (bit + 1);\n    buf = OPENSSL_malloc(bytes);\n    if (buf == NULL) {\n        BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    time(&tim);\n    RAND_add(&tim, sizeof(tim), 0.0);\n    if (pseudorand) {\n        if (RAND_bytes(buf, bytes) <= 0)\n            goto err;\n    } else {\n        if (RAND_bytes(buf, bytes) <= 0)\n            goto err;\n    }\n    if (pseudorand == 2) {\n        int i;\n        unsigned char c;\n        for (i = 0; i < bytes; i++) {\n            if (RAND_bytes(&c, 1) <= 0)\n                goto err;\n            if (c >= 128 && i > 0)\n                buf[i] = buf[i - 1];\n            else if (c < 42)\n                buf[i] = 0;\n            else if (c < 84)\n                buf[i] = 255;\n        }\n    }\n    if (top >= 0) {\n        if (top) {\n            if (bit == 0) {\n                buf[0] = 1;\n                buf[1] |= 0x80;\n            } else {\n                buf[0] |= (3 << (bit - 1));\n            }\n        } else {\n            buf[0] |= (1 << bit);\n        }\n    }\n    buf[0] &= ~mask;\n    if (bottom)\n        buf[bytes - 1] |= 1;\n    if (!BN_bin2bn(buf, bytes, rnd))\n        goto err;\n    ret = 1;\n err:\n    OPENSSL_clear_free(buf, bytes);\n    bn_check_top(rnd);\n    return (ret);\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n    BN_ULONG *ap, *rp, t, c;\n    int i, j;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (BN_is_zero(a)) {\n        BN_zero(r);\n        return (1);\n    }\n    i = a->top;\n    ap = a->d;\n    j = i - (ap[i - 1] == 1);\n    if (a != r) {\n        if (bn_wexpand(r, j) == NULL)\n            return (0);\n        r->neg = a->neg;\n    }\n    rp = r->d;\n    t = ap[--i];\n    c = (t & 1) ? BN_TBIT : 0;\n    if (t >>= 1)\n        rp[i] = t;\n    while (i > 0) {\n        t = ap[--i];\n        rp[i] = ((t >> 1) & BN_MASK2) | c;\n        c = (t & 1) ? BN_TBIT : 0;\n    }\n    r->top = j;\n    bn_check_top(r);\n    return (1);\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}']