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


test/bntest.c:1902:5: Call
1900.       c = BN_new();
1901.       d = BN_new();
1902.       BN_one(c);
            ^
1903.   
1904.       if (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);

test/bntest.c:1908:9: Call
1906.       else {
1907.           a = BN_new();
1908.           BN_bntest_rand(a, 200, 0, 0);
                ^
1909.           a->neg = rand_neg();
1910.       }

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;

crypto/bn/bn_rand.c:131:9: Call
    129.   
    130.       if (bits == 0) {
    131.           BN_zero(rnd);
                   ^
    132.           return 1;
    133.       }

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_bntest_rand` 
      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_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_)\n{\n    BIGNUM *a, *b, *c, *d;\n    int i;\n    b = BN_new();\n    c = BN_new();\n    d = BN_new();\n    BN_one(c);\n    if (a_)\n        a = a_;\n    else {\n        a = BN_new();\n        BN_bntest_rand(a, 200, 0, 0);\n        a->neg = rand_neg();\n    }\n    for (i = 0; i < num0; i++) {\n        BN_lshift(b, a, i + 1);\n        BN_add(c, c, c);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " * ");\n                BN_print(bp, c);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, b);\n            BIO_puts(bp, "\\n");\n        }\n        BN_mul(d, a, c, ctx);\n        BN_sub(d, d, b);\n        if (!BN_is_zero(d)) {\n            fprintf(stderr, "Left shift test failed!\\n");\n            fprintf(stderr, "a=");\n            BN_print_fp(stderr, a);\n            fprintf(stderr, "\\nb=");\n            BN_print_fp(stderr, b);\n            fprintf(stderr, "\\nc=");\n            BN_print_fp(stderr, c);\n            fprintf(stderr, "\\nd=");\n            BN_print_fp(stderr, d);\n            fprintf(stderr, "\\n");\n            return 0;\n        }\n    }\n    BN_free(a);\n    BN_free(b);\n    BN_free(c);\n    BN_free(d);\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}', '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}']