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


test/drbgtest.c:470:9: Call
468.       int rv = 0;
469.   
470.       if (error_check(td))
               ^
471.           goto err;
472.       rv = 1;

test/drbgtest.c:271:1: Parameter `td->exlen`
  269.    * Induce several failure modes and check an error condition is set.
  270.    */
  271. > static int error_check(DRBG_SELFTEST_DATA *td)
  272.   {
  273.       static char zero[sizeof(DRBG_CTX)];

test/drbgtest.c:302:10: Call
  300.   
  301.       /* Try to generate output from uninstantiated DRBG */
  302.       if (!TEST_false(RAND_DRBG_generate(dctx, buff, td->exlen, 0,
                  ^
  303.                                          td->adin, td->adinlen))
  304.               || !uninstantiate(dctx))

crypto/rand/drbg_lib.c:258:1: Parameter `outlen`
    256.    * sent in |adin| and |adinlen|.
    257.    */
    258. > int RAND_DRBG_generate(DRBG_CTX *dctx, unsigned char *out, size_t outlen,
    259.                          int prediction_resistance,
    260.                          const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_lib.c:294:10: Call
    292.       }
    293.   
    294.       if (!ctr_generate(dctx, out, outlen, adin, adinlen)) {
                    ^
    295.           r = RAND_R_GENERATE_ERROR;
    296.           dctx->status = DRBG_STATUS_ERROR;

crypto/rand/drbg_rand.c:280:1: <Offset trace>
278.   }
279.   
280. > int ctr_generate(DRBG_CTX *dctx,
281.                    unsigned char *out, size_t outlen,
282.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:280:1: Parameter `outlen`
      278.   }
      279.   
      280. > int ctr_generate(DRBG_CTX *dctx,
      281.                    unsigned char *out, size_t outlen,
      282.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:280:1: <Length trace>
278.   }
279.   
280. > int ctr_generate(DRBG_CTX *dctx,
281.                    unsigned char *out, size_t outlen,
282.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:280:1: Parameter `dctx->ctr.K[*]`
      278.   }
      279.   
      280. > int ctr_generate(DRBG_CTX *dctx,
      281.                    unsigned char *out, size_t outlen,
      282.                    const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_rand.c:302:13: Array access: Offset added: [0, 15] Size: [0, +oo] by call to `error_check` 
      300.               /* Use K as temp space as it will be updated */
      301.               AES_encrypt(cctx->V, cctx->K, &cctx->ks);
      302.               memcpy(out, cctx->K, outlen);
                         ^
      303.               break;
      304.           }

int ctr_generate(DRBG_CTX *dctx,
                 unsigned char *out, size_t outlen,
                 const unsigned char *adin, size_t adinlen)
{
    DRBG_CTR_CTX *cctx = &dctx->ctr;
    if (adin != NULL && adinlen != 0) {
        ctr_update(dctx, adin, adinlen, NULL, 0, NULL, 0);
        if (dctx->flags & RAND_DRBG_FLAG_CTR_USE_DF) {
            adin = NULL;
            adinlen = 1;
        }
    } else {
        adinlen = 0;
    }
    for ( ; ; ) {
        inc_128(cctx);
        if (outlen < 16) {
            AES_encrypt(cctx->V, cctx->K, &cctx->ks);
            memcpy(out, cctx->K, outlen);
            break;
        }
        AES_encrypt(cctx->V, out, &cctx->ks);
        out += 16;
        outlen -= 16;
        if (outlen == 0)
            break;
    }
    ctr_update(dctx, adin, adinlen, NULL, 0, NULL, 0);
    return 1;
}
['static int test_error_checks(int i)\n{\n    DRBG_SELFTEST_DATA *td = &drbg_test[i];\n    int rv = 0;\n    if (error_check(td))\n        goto err;\n    rv = 1;\nerr:\n    return rv;\n}', 'static int error_check(DRBG_SELFTEST_DATA *td)\n{\n    static char zero[sizeof(DRBG_CTX)];\n    DRBG_CTX *dctx = NULL;\n    TEST_CTX t;\n    unsigned char buff[1024];\n    unsigned int reseed_counter_tmp;\n    int ret = 0;\n    if (!TEST_ptr(dctx = RAND_DRBG_new(0, 0, NULL)))\n        goto err;\n    if (!init(dctx, td, &t)\n            || RAND_DRBG_instantiate(dctx, td->pers, dctx->max_pers + 1) > 0)\n        goto err;\n    t.entlen = 0;\n    if (TEST_int_le(RAND_DRBG_instantiate(dctx, td->pers, td->perslen), 0))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(dctx, buff, td->exlen, 0,\n                                       td->adin, td->adinlen))\n            || !uninstantiate(dctx))\n        goto err;\n    t.entlen = dctx->min_entropy - 1;\n    if (!init(dctx, td, &t)\n            || RAND_DRBG_instantiate(dctx, td->pers, td->perslen) > 0\n            || !uninstantiate(dctx))\n        goto err;\n    t.entlen = dctx->max_entropy + 1;\n    if (!init(dctx, td, &t)\n            || RAND_DRBG_instantiate(dctx, td->pers, td->perslen) > 0\n            || !uninstantiate(dctx))\n        goto err;\n    if (dctx->min_nonce) {\n        t.noncelen = dctx->min_nonce - 1;\n        if (!init(dctx, td, &t)\n                || RAND_DRBG_instantiate(dctx, td->pers, td->perslen) > 0\n                || !uninstantiate(dctx))\n            goto err;\n    }\n    if (dctx->max_nonce) {\n        t.noncelen = dctx->max_nonce + 1;\n        if (!init(dctx, td, &t)\n                || RAND_DRBG_instantiate(dctx, td->pers, td->perslen) > 0\n                || !uninstantiate(dctx))\n            goto err;\n    }\n    if (!instantiate(dctx, td, &t)\n            || !TEST_true(RAND_DRBG_generate(dctx, buff, td->exlen, 0,\n                                             td->adin, td->adinlen)))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(dctx, buff, dctx->max_request + 1, 0,\n                                       td->adin, td->adinlen)))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(dctx, buff, td->exlen, 0,\n                                       td->adin, dctx->max_adin + 1)))\n        goto err;\n    t.entlen = 0;\n    if (TEST_false(RAND_DRBG_generate(dctx, buff, td->exlen, 1,\n                                      td->adin, td->adinlen))\n            || !uninstantiate(dctx))\n        goto err;\n    if (!instantiate(dctx, td, &t))\n        goto err;\n    reseed_counter_tmp = dctx->reseed_counter;\n    dctx->reseed_counter = dctx->reseed_interval;\n    t.entcnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(dctx, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entcnt, 1)\n            || !TEST_int_eq(dctx->reseed_counter, reseed_counter_tmp + 1)\n            || !uninstantiate(dctx))\n        goto err;\n    t.entlen = 0;\n    if (!TEST_false(RAND_DRBG_generate(dctx, buff, td->exlen, 1,\n                                       td->adin, td->adinlen))\n            || !uninstantiate(dctx))\n        goto err;\n    if (!instantiate(dctx, td, &t))\n        goto err;\n    reseed_counter_tmp = dctx->reseed_counter;\n    dctx->reseed_counter = dctx->reseed_interval;\n    t.entcnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(dctx, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entcnt, 1)\n            || !TEST_int_eq(dctx->reseed_counter, reseed_counter_tmp + 1)\n            || !uninstantiate(dctx))\n        goto err;\n    if (!init(dctx, td, &t)\n            || RAND_DRBG_reseed(dctx, td->adin, dctx->max_adin + 1) > 0)\n        goto err;\n    t.entlen = 0;\n    if (!TEST_int_le(RAND_DRBG_reseed(dctx, td->adin, td->adinlen), 0)\n            || !uninstantiate(dctx))\n        goto err;\n    if (!init(dctx, td, &t))\n        goto err;\n    t.entlen = dctx->max_entropy + 1;\n    if (!TEST_int_le(RAND_DRBG_reseed(dctx, td->adin, td->adinlen), 0)\n            || !uninstantiate(dctx))\n        goto err;\n    if (!init(dctx, td, &t))\n        goto err;\n    t.entlen = dctx->min_entropy - 1;\n    if (!TEST_int_le(RAND_DRBG_reseed(dctx, td->adin, td->adinlen), 0)\n            || !uninstantiate(dctx))\n        goto err;\n    if (!TEST_mem_eq(zero, sizeof(dctx->ctr), &dctx->ctr, sizeof(dctx->ctr)))\n        goto err;\n    ret = 1;\nerr:\n    uninstantiate(dctx);\n    RAND_DRBG_free(dctx);\n    return ret;\n}', 'int RAND_DRBG_generate(DRBG_CTX *dctx, unsigned char *out, size_t outlen,\n                       int prediction_resistance,\n                       const unsigned char *adin, size_t adinlen)\n{\n    int r = 0;\n    if (dctx->status != DRBG_STATUS_READY\n            && dctx->status != DRBG_STATUS_RESEED) {\n        if (dctx->status == DRBG_STATUS_ERROR)\n            r = RAND_R_IN_ERROR_STATE;\n        else if(dctx->status == DRBG_STATUS_UNINITIALISED)\n            r = RAND_R_NOT_INSTANTIATED;\n        goto end;\n    }\n    if (outlen > dctx->max_request) {\n        r = RAND_R_REQUEST_TOO_LARGE_FOR_DRBG;\n        return 0;\n    }\n    if (adinlen > dctx->max_adin) {\n        r = RAND_R_ADDITIONAL_INPUT_TOO_LONG;\n        goto end;\n    }\n    if (dctx->reseed_counter >= dctx->reseed_interval)\n        dctx->status = DRBG_STATUS_RESEED;\n    if (dctx->status == DRBG_STATUS_RESEED || prediction_resistance) {\n        if (!RAND_DRBG_reseed(dctx, adin, adinlen)) {\n            r = RAND_R_RESEED_ERROR;\n            goto end;\n        }\n        adin = NULL;\n        adinlen = 0;\n    }\n    if (!ctr_generate(dctx, out, outlen, adin, adinlen)) {\n        r = RAND_R_GENERATE_ERROR;\n        dctx->status = DRBG_STATUS_ERROR;\n        goto end;\n    }\n    if (dctx->reseed_counter >= dctx->reseed_interval)\n        dctx->status = DRBG_STATUS_RESEED;\n    else\n        dctx->reseed_counter++;\n    return 1;\nend:\n    RANDerr(RAND_F_RAND_DRBG_GENERATE, r);\n    return 0;\n}', 'int ctr_generate(DRBG_CTX *dctx,\n                 unsigned char *out, size_t outlen,\n                 const unsigned char *adin, size_t adinlen)\n{\n    DRBG_CTR_CTX *cctx = &dctx->ctr;\n    if (adin != NULL && adinlen != 0) {\n        ctr_update(dctx, adin, adinlen, NULL, 0, NULL, 0);\n        if (dctx->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(cctx);\n        if (outlen < 16) {\n            AES_encrypt(cctx->V, cctx->K, &cctx->ks);\n            memcpy(out, cctx->K, outlen);\n            break;\n        }\n        AES_encrypt(cctx->V, out, &cctx->ks);\n        out += 16;\n        outlen -= 16;\n        if (outlen == 0)\n            break;\n    }\n    ctr_update(dctx, adin, adinlen, NULL, 0, NULL, 0);\n    return 1;\n}']