apps/apps.c:1472: error: BUFFER_OVERRUN_L3
  Offset: [-1, 70] Size: [1, 71] by call to `BN_pseudo_rand`.
Showing all 12 steps of the trace


apps/apps.c:1472:10: Call
1470.           return 0;
1471.   
1472.       if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
                 ^
1473.           goto error;
1474.       if (ai && !BN_to_ASN1_INTEGER(btmp, ai))

crypto/bn/bn_rand.c:101:1: Parameter `bits`
  99.   }
  100.   
  101. > int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
  102.   {
  103.       return bnrand(1, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:103:12: Call
  101.   int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
  102.   {
  103.       return bnrand(1, rnd, bits, top, bottom);
                    ^
  104.   }
  105.   

crypto/bn/bn_rand.c:56:14: <Offset trace>
54.           unsigned char c;
55.   
56.           for (i = 0; i < bytes; i++) {
                   ^
57.               if (RAND_bytes(&c, 1) <= 0)
58.                   goto err;

crypto/bn/bn_rand.c:56:14: Assignment
    54.           unsigned char c;
    55.   
    56.           for (i = 0; i < bytes; i++) {
                       ^
    57.               if (RAND_bytes(&c, 1) <= 0)
    58.                   goto err;

crypto/bn/bn_rand.c:17:1: <Length trace>
15.   #include <openssl/sha.h>
16.   
17. > static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
18.   {
19.       unsigned char *buf = NULL;

crypto/bn/bn_rand.c:17:1: Parameter `bits`
    15.   #include <openssl/sha.h>
    16.   
    17. > static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
    18.   {
    19.       unsigned char *buf = NULL;

crypto/bn/bn_rand.c:32:5: Assignment
    30.           goto toosmall;
    31.   
    32.       bytes = (bits + 7) / 8;
              ^
    33.       bit = (bits - 1) % 8;
    34.       mask = 0xff << (bit + 1);

crypto/bn/bn_rand.c:36:11: Call
    34.       mask = 0xff << (bit + 1);
    35.   
    36.       buf = OPENSSL_malloc(bytes);
                    ^
    37.       if (buf == NULL) {
    38.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);

crypto/mem.c:79:9: Assignment
      77.   
      78.       if (num <= 0)
      79.           return NULL;
                    ^
      80.   
      81.       allow_customize = 0;

crypto/bn/bn_rand.c:36:5: Assignment
    34.       mask = 0xff << (bit + 1);
    35.   
    36.       buf = OPENSSL_malloc(bytes);
              ^
    37.       if (buf == NULL) {
    38.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_rand.c:82:9: Array access: Offset: [-1, 70] Size: [1, 71] by call to `BN_pseudo_rand` 
    80.       buf[0] &= ~mask;
    81.       if (bottom)                 /* set bottom bit if requested */
    82.           buf[bytes - 1] |= 1;
                  ^
    83.       if (!BN_bin2bn(buf, bytes, rnd))
    84.           goto err;

static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
{
    unsigned char *buf = NULL;
    int ret = 0, bit, bytes, mask;
    time_t tim;
    if (bits == 0) {
        if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)
            goto toosmall;
        BN_zero(rnd);
        return 1;
    }
    if (bits < 0 || (bits == 1 && top > 0))
        goto toosmall;
    bytes = (bits + 7) / 8;
    bit = (bits - 1) % 8;
    mask = 0xff << (bit + 1);
    buf = OPENSSL_malloc(bytes);
    if (buf == NULL) {
        BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    time(&tim);
    RAND_add(&tim, sizeof(tim), 0.0);
    if (RAND_bytes(buf, bytes) <= 0)
        goto err;
    if (pseudorand == 2) {
        int i;
        unsigned char c;
        for (i = 0; i < bytes; i++) {
            if (RAND_bytes(&c, 1) <= 0)
                goto err;
            if (c >= 128 && i > 0)
                buf[i] = buf[i - 1];
            else if (c < 42)
                buf[i] = 0;
            else if (c < 84)
                buf[i] = 255;
        }
    }
    if (top >= 0) {
        if (top) {
            if (bit == 0) {
                buf[0] = 1;
                buf[1] |= 0x80;
            } else {
                buf[0] |= (3 << (bit - 1));
            }
        } else {
            buf[0] |= (1 << bit);
        }
    }
    buf[0] &= ~mask;
    if (bottom)
        buf[bytes - 1] |= 1;
    if (!BN_bin2bn(buf, bytes, rnd))
        goto err;
    ret = 1;
 err:
    OPENSSL_clear_free(buf, bytes);
    bn_check_top(rnd);
    return (ret);
toosmall:
    BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);
    return 0;
}
['int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)\n{\n    BIGNUM *btmp;\n    int ret = 0;\n    if (b)\n        btmp = b;\n    else\n        btmp = BN_new();\n    if (btmp == NULL)\n        return 0;\n    if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))\n        goto error;\n    if (ai && !BN_to_ASN1_INTEGER(btmp, ai))\n        goto error;\n    ret = 1;\n error:\n    if (btmp != b)\n        BN_free(btmp);\n    return ret;\n}', 'int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n    return bnrand(1, 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) {\n        if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n            goto toosmall;\n        BN_zero(rnd);\n        return 1;\n    }\n    if (bits < 0 || (bits == 1 && top > 0))\n        goto toosmall;\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 (RAND_bytes(buf, bytes) <= 0)\n        goto err;\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);\ntoosmall:\n    BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n    return 0;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']