crypto/rand/rand_lib.c:165: error: BUFFER_OVERRUN_L3
  Offset added: [0, 15] Size: [0, +oo] by call to `RAND_DRBG_generate`.
Showing all 11 steps of the trace


crypto/rand/rand_lib.c:152:31: Call
150.   
151.       if (drbg->parent) {
152.           size_t bytes_needed = RAND_POOL_bytes_needed(pool, 8);
                                     ^
153.           unsigned char *buffer = RAND_POOL_add_begin(pool, bytes_needed);
154.   

crypto/rand/rand_lib.c:440:9: Assignment
  438.       if (entropy_per_byte < 1 || entropy_per_byte > 8) {
  439.           RANDerr(RAND_F_RAND_POOL_BYTES_NEEDED, RAND_R_ARGUMENT_OUT_OF_RANGE);
  440.           return 0;
                 ^
  441.       }
  442.   

crypto/rand/rand_lib.c:152:9: Assignment
150.   
151.       if (drbg->parent) {
152.           size_t bytes_needed = RAND_POOL_bytes_needed(pool, 8);
               ^
153.           unsigned char *buffer = RAND_POOL_add_begin(pool, bytes_needed);
154.   

crypto/rand/rand_lib.c:165:17: Call
163.               if (drbg->parent->lock)
164.                   CRYPTO_THREAD_write_lock(drbg->parent->lock);
165.               if (RAND_DRBG_generate(drbg->parent,
                       ^
166.                                      buffer, bytes_needed,
167.                                      0,

crypto/rand/drbg_lib.c:363:1: Parameter `outlen`
  361.    *
  362.    */
  363. > int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
  364.                          int prediction_resistance,
  365.                          const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_lib.c:409:10: Call
  407.       }
  408.   
  409.       if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {
                  ^
  410.           drbg->state = DRBG_ERROR;
  411.           RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_GENERATE_ERROR);

crypto/rand/drbg_rand.c:266:1: <Offset trace>
264.   }
265.   
266. > int ctr_generate(RAND_DRBG *drbg,
267.                    unsigned char *out, size_t outlen,
268.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:266:1: Parameter `outlen`
    264.   }
    265.   
    266. > int ctr_generate(RAND_DRBG *drbg,
    267.                    unsigned char *out, size_t outlen,
    268.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:266:1: <Length trace>
264.   }
265.   
266. > int ctr_generate(RAND_DRBG *drbg,
267.                    unsigned char *out, size_t outlen,
268.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:266:1: Parameter `drbg->ctr.K[*]`
    264.   }
    265.   
    266. > int ctr_generate(RAND_DRBG *drbg,
    267.                    unsigned char *out, size_t outlen,
    268.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:288:13: Array access: Offset added: [0, 15] Size: [0, +oo] by call to `RAND_DRBG_generate` 
    286.               /* Use K as temp space as it will be updated */
    287.               AES_encrypt(ctr->V, ctr->K, &ctr->ks);
    288.               memcpy(out, ctr->K, outlen);
                       ^
    289.               break;
    290.           }

int ctr_generate(RAND_DRBG *drbg,
                 unsigned char *out, size_t outlen,
                 const unsigned char *adin, size_t adinlen)
{
    RAND_DRBG_CTR *ctr = &drbg->ctr;
    if (adin != NULL && adinlen != 0) {
        ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0);
        if (drbg->flags & RAND_DRBG_FLAG_CTR_USE_DF) {
            adin = NULL;
            adinlen = 1;
        }
    } else {
        adinlen = 0;
    }
    for ( ; ; ) {
        inc_128(ctr);
        if (outlen < 16) {
            AES_encrypt(ctr->V, ctr->K, &ctr->ks);
            memcpy(out, ctr->K, outlen);
            break;
        }
        AES_encrypt(ctr->V, out, &ctr->ks);
        out += 16;
        outlen -= 16;
        if (outlen == 0)
            break;
    }
    ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0);
    return 1;
}
['size_t rand_drbg_get_entropy(RAND_DRBG *drbg,\n                        unsigned char **pout,\n                        int entropy, size_t min_len, size_t max_len)\n{\n    size_t ret = 0;\n    size_t entropy_available = 0;\n    RAND_POOL *pool = RAND_POOL_new(entropy, min_len, max_len);\n    if (pool == NULL)\n        return 0;\n    if (drbg->pool) {\n        RAND_POOL_add(pool,\n                      RAND_POOL_buffer(drbg->pool),\n                      RAND_POOL_length(drbg->pool),\n                      RAND_POOL_entropy(drbg->pool));\n        RAND_POOL_free(drbg->pool);\n        drbg->pool = NULL;\n    }\n    if (drbg->parent) {\n        size_t bytes_needed = RAND_POOL_bytes_needed(pool, 8);\n        unsigned char *buffer = RAND_POOL_add_begin(pool, bytes_needed);\n        if (buffer != NULL) {\n            size_t bytes = 0;\n            if (drbg->parent->lock)\n                CRYPTO_THREAD_write_lock(drbg->parent->lock);\n            if (RAND_DRBG_generate(drbg->parent,\n                                   buffer, bytes_needed,\n                                   0,\n                                   (unsigned char *)drbg, sizeof(*drbg)) != 0)\n                bytes = bytes_needed;\n            if (drbg->parent->lock)\n                CRYPTO_THREAD_unlock(drbg->parent->lock);\n            entropy_available = RAND_POOL_add_end(pool, bytes, 8 * bytes);\n        }\n    } else {\n        entropy_available = RAND_POOL_acquire_entropy(pool);\n    }\n    if (entropy_available > 0) {\n        ret   = RAND_POOL_length(pool);\n        *pout = RAND_POOL_detach(pool);\n    }\n    RAND_POOL_free(pool);\n    return ret;\n}', 'size_t RAND_POOL_bytes_needed(RAND_POOL *pool, unsigned int entropy_per_byte)\n{\n    size_t bytes_needed;\n    size_t entropy_needed = RAND_POOL_entropy_needed(pool);\n    if (entropy_per_byte < 1 || entropy_per_byte > 8) {\n        RANDerr(RAND_F_RAND_POOL_BYTES_NEEDED, RAND_R_ARGUMENT_OUT_OF_RANGE);\n        return 0;\n    }\n    bytes_needed = ENTROPY_TO_BYTES(entropy_needed, entropy_per_byte);\n    if (bytes_needed > pool->max_len - pool->len) {\n        RANDerr(RAND_F_RAND_POOL_BYTES_NEEDED, RAND_R_RANDOM_POOL_OVERFLOW);\n        return 0;\n    }\n    if (pool->len < pool->min_len &&\n        bytes_needed < pool->min_len - pool->len)\n        bytes_needed = pool->min_len - pool->len;\n    return bytes_needed;\n}', 'int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,\n                       int prediction_resistance,\n                       const unsigned char *adin, size_t adinlen)\n{\n    int reseed_required = 0;\n    if (drbg->state != DRBG_READY) {\n        rand_drbg_restart(drbg, NULL, 0, 0);\n        if (drbg->state == DRBG_ERROR) {\n            RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_IN_ERROR_STATE);\n            return 0;\n        }\n        if (drbg->state == DRBG_UNINITIALISED) {\n            RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_NOT_INSTANTIATED);\n            return 0;\n        }\n    }\n    if (outlen > drbg->max_request) {\n        RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_REQUEST_TOO_LARGE_FOR_DRBG);\n        return 0;\n    }\n    if (adinlen > drbg->max_adinlen) {\n        RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_ADDITIONAL_INPUT_TOO_LONG);\n        return 0;\n    }\n    if (drbg->fork_count != rand_fork_count) {\n        drbg->fork_count = rand_fork_count;\n        reseed_required = 1;\n    }\n    if (drbg->reseed_counter >= drbg->reseed_interval)\n        reseed_required = 1;\n    if (reseed_required || prediction_resistance) {\n        if (!RAND_DRBG_reseed(drbg, adin, adinlen)) {\n            RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_RESEED_ERROR);\n            return 0;\n        }\n        adin = NULL;\n        adinlen = 0;\n    }\n    if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {\n        drbg->state = DRBG_ERROR;\n        RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_GENERATE_ERROR);\n        return 0;\n    }\n    drbg->reseed_counter++;\n    return 1;\n}', 'int ctr_generate(RAND_DRBG *drbg,\n                 unsigned char *out, size_t outlen,\n                 const unsigned char *adin, size_t adinlen)\n{\n    RAND_DRBG_CTR *ctr = &drbg->ctr;\n    if (adin != NULL && adinlen != 0) {\n        ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0);\n        if (drbg->flags & RAND_DRBG_FLAG_CTR_USE_DF) {\n            adin = NULL;\n            adinlen = 1;\n        }\n    } else {\n        adinlen = 0;\n    }\n    for ( ; ; ) {\n        inc_128(ctr);\n        if (outlen < 16) {\n            AES_encrypt(ctr->V, ctr->K, &ctr->ks);\n            memcpy(out, ctr->K, outlen);\n            break;\n        }\n        AES_encrypt(ctr->V, out, &ctr->ks);\n        out += 16;\n        outlen -= 16;\n        if (outlen == 0)\n            break;\n    }\n    ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0);\n    return 1;\n}']