test/drbgtest.c:350: error: BUFFER_OVERRUN_L3
  Offset added: [1, 15] Size: [0, +oo] by call to `RAND_DRBG_generate`.
Showing all 11 steps of the trace


test/drbgtest.c:280:10: Call
278.       int ret = 0;
279.   
280.       if (!TEST_ptr(drbg = RAND_DRBG_new(0, 0, NULL)))
                ^
281.           goto err;
282.   

crypto/rand/drbg_lib.c:152:9: Call
  150.       drbg->fork_count = rand_fork_count;
  151.       drbg->parent = parent;
  152.       if (RAND_DRBG_set(drbg, type, flags) == 0)
                 ^
  153.           goto err;
  154.   

crypto/rand/drbg_lib.c:109:1: Parameter `drbg->max_request`
    107.    * Returns 1 on success, 0 on failure.
    108.    */
    109. > int RAND_DRBG_set(RAND_DRBG *drbg, int nid, unsigned int flags)
    110.   {
    111.       int ret = 1;

test/drbgtest.c:350:10: Call
348.   
349.       /* Request too much data for one request */
350.       if (!TEST_false(RAND_DRBG_generate(drbg, buff, drbg->max_request + 1, 0,
                ^
351.                                          td->adin, td->adinlen)))
352.           goto err;

crypto/rand/drbg_lib.c:452:1: Parameter `outlen`
  450.    *
  451.    */
  452. > int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
  453.                          int prediction_resistance,
  454.                          const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_lib.c:510:10: Call
  508.       }
  509.   
  510.       if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {
                  ^
  511.           drbg->state = DRBG_ERROR;
  512.           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: [1, 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;
}
['static int error_check(DRBG_SELFTEST_DATA *td)\n{\n    static char zero[sizeof(RAND_DRBG)];\n    RAND_DRBG *drbg = NULL;\n    TEST_CTX t;\n    unsigned char buff[1024];\n    unsigned int generate_counter_tmp;\n    int ret = 0;\n    if (!TEST_ptr(drbg = RAND_DRBG_new(0, 0, NULL)))\n        goto err;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_instantiate(drbg, td->pers, drbg->max_perslen + 1) > 0)\n        goto err;\n    t.entropylen = 0;\n    if (TEST_int_le(RAND_DRBG_instantiate(drbg, td->pers, td->perslen), 0))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                       td->adin, td->adinlen))\n            || !uninstantiate(drbg))\n        goto err;\n    t.entropylen = drbg->min_entropylen - 1;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n            || !uninstantiate(drbg))\n        goto err;\n    t.entropylen = drbg->max_entropylen + 1;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n            || !uninstantiate(drbg))\n        goto err;\n    if (drbg->min_noncelen) {\n        t.noncelen = drbg->min_noncelen - 1;\n        if (!init(drbg, td, &t)\n                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n                || !uninstantiate(drbg))\n            goto err;\n    }\n    if (drbg->max_noncelen) {\n        t.noncelen = drbg->max_noncelen + 1;\n        if (!init(drbg, td, &t)\n                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n                || !uninstantiate(drbg))\n            goto err;\n    }\n    if (!instantiate(drbg, td, &t)\n            || !TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                             td->adin, td->adinlen)))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, drbg->max_request + 1, 0,\n                                       td->adin, td->adinlen)))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                       td->adin, drbg->max_adinlen + 1)))\n        goto err;\n    t.entropylen = 0;\n    if (TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,\n                                      td->adin, td->adinlen))\n            || !uninstantiate(drbg))\n        goto err;\n    if (!instantiate(drbg, td, &t))\n        goto err;\n    generate_counter_tmp = drbg->generate_counter;\n    drbg->generate_counter = drbg->reseed_interval;\n    t.entropycnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entropycnt, 1)\n            || !TEST_int_eq(drbg->generate_counter, generate_counter_tmp + 1)\n            || !uninstantiate(drbg))\n        goto err;\n    t.entropylen = 0;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,\n                                       td->adin, td->adinlen))\n            || !uninstantiate(drbg))\n        goto err;\n    if (!instantiate(drbg, td, &t))\n        goto err;\n    generate_counter_tmp = drbg->generate_counter;\n    drbg->generate_counter = drbg->reseed_interval;\n    t.entropycnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entropycnt, 1)\n            || !TEST_int_eq(drbg->generate_counter, generate_counter_tmp + 1)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_reseed(drbg, td->adin, drbg->max_adinlen + 1) > 0)\n        goto err;\n    t.entropylen = 0;\n    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t))\n        goto err;\n    t.entropylen = drbg->max_entropylen + 1;\n    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t))\n        goto err;\n    t.entropylen = drbg->min_entropylen - 1;\n    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!TEST_mem_eq(zero, sizeof(drbg->ctr), &drbg->ctr, sizeof(drbg->ctr)))\n        goto err;\n    ret = 1;\nerr:\n    uninstantiate(drbg);\n    RAND_DRBG_free(drbg);\n    return ret;\n}', 'RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent)\n{\n    RAND_DRBG *drbg = OPENSSL_zalloc(sizeof(*drbg));\n    if (drbg == NULL) {\n        RANDerr(RAND_F_RAND_DRBG_NEW, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    drbg->fork_count = rand_fork_count;\n    drbg->parent = parent;\n    if (RAND_DRBG_set(drbg, type, flags) == 0)\n        goto err;\n    if (!RAND_DRBG_set_callbacks(drbg, rand_drbg_get_entropy,\n                                 rand_drbg_cleanup_entropy,\n                                 NULL, NULL))\n        goto err;\n    return drbg;\nerr:\n    OPENSSL_free(drbg);\n    return NULL;\n}', 'int RAND_DRBG_set(RAND_DRBG *drbg, int nid, unsigned int flags)\n{\n    int ret = 1;\n    drbg->state = DRBG_UNINITIALISED;\n    drbg->flags = flags;\n    drbg->nid = nid;\n    switch (nid) {\n    default:\n        RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_UNSUPPORTED_DRBG_TYPE);\n        return 0;\n    case 0:\n        return 1;\n    case NID_aes_128_ctr:\n    case NID_aes_192_ctr:\n    case NID_aes_256_ctr:\n        ret = ctr_init(drbg);\n        break;\n    }\n    if (ret == 0)\n        RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_ERROR_INITIALISING_DRBG);\n    return ret;\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_interval > 0) {\n        if (drbg->generate_counter >= drbg->reseed_interval)\n            reseed_required = 1;\n    }\n    if (drbg->reseed_time_interval > 0) {\n        time_t now = time(NULL);\n        if (now < drbg->reseed_time\n            || now - drbg->reseed_time >= drbg->reseed_time_interval)\n            reseed_required = 1;\n    }\n    if (drbg->reseed_counter > 0 && drbg->parent != NULL) {\n        if (drbg->reseed_counter != drbg->parent->reseed_counter)\n            reseed_required = 1;\n    }\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->generate_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}']