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


test/drbgtest.c:457:10: Call
455.       int rv = 0;
456.   
457.       if (!single_kat(td))
                ^
458.           goto err;
459.       rv = 1;

test/drbgtest.c:148:1: Parameter `td->exlen`
  146.    * Do a single KAT test.  Return 0 on failure.
  147.    */
  148. > static int single_kat(DRBG_SELFTEST_DATA *td)
  149.   {
  150.       RAND_DRBG *drbg = NULL;

test/drbgtest.c:174:17: Call
  172.   
  173.       if (!TEST_true(RAND_DRBG_instantiate(drbg, td->pers, td->perslen))
  174.               || !TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                         ^
  175.                                                td->adin, td->adinlen))
  176.               || !TEST_mem_eq(td->expected, td->exlen, buff, td->exlen))

crypto/rand/drbg_lib.c:355:1: Parameter `outlen`
    353.    *
    354.    */
    355. > int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
    356.                          int prediction_resistance,
    357.                          const unsigned char *adin, size_t adinlen)

crypto/rand/drbg_lib.c:401:10: Call
    399.       }
    400.   
    401.       if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {
                    ^
    402.           drbg->state = DRBG_ERROR;
    403.           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 `single_kat` 
      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 test_kats(int i)\n{\n    DRBG_SELFTEST_DATA *td = &drbg_test[i];\n    int rv = 0;\n    if (!single_kat(td))\n        goto err;\n    rv = 1;\nerr:\n    return rv;\n}', 'static int single_kat(DRBG_SELFTEST_DATA *td)\n{\n    RAND_DRBG *drbg = NULL;\n    TEST_CTX t;\n    int failures = 0;\n    unsigned char buff[1024];\n    if (!TEST_ptr(drbg = RAND_DRBG_new(td->nid, td->flags, NULL)))\n        return 0;\n    if (!TEST_true(RAND_DRBG_set_callbacks(drbg, kat_entropy, NULL,\n                                           kat_nonce, NULL))) {\n        failures++;\n        goto err;\n    }\n    memset(&t, 0, sizeof(t));\n    t.entropy = td->entropy;\n    t.entropylen = td->entropylen;\n    t.nonce = td->nonce;\n    t.noncelen = td->noncelen;\n    RAND_DRBG_set_ex_data(drbg, app_data_index, &t);\n    if (!TEST_true(RAND_DRBG_instantiate(drbg, td->pers, td->perslen))\n            || !TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                             td->adin, td->adinlen))\n            || !TEST_mem_eq(td->expected, td->exlen, buff, td->exlen))\n        failures++;\n    t.entropy = td->entropyreseed;\n    t.entropylen = td->entropyreseedlen;\n    if (!TEST_true(RAND_DRBG_reseed(drbg, td->adinreseed, td->adinreseedlen)\n            || !TEST_true(RAND_DRBG_generate(drbg, buff, td->kat2len, 0,\n                                             td->adin2, td->adin2len))\n            || !TEST_mem_eq(td->kat2, td->kat2len, buff, td->kat2len)))\n        failures++;\n    uninstantiate(drbg);\n    if (!TEST_true(RAND_DRBG_set(drbg, td->nid, td->flags))\n            || !TEST_true(RAND_DRBG_set_callbacks(drbg, kat_entropy, NULL,\n                                                  kat_nonce, NULL)))\n        failures++;\n    RAND_DRBG_set_ex_data(drbg, app_data_index, &t);\n    t.entropy = td->entropy_pr;\n    t.entropylen = td->entropylen_pr;\n    t.nonce = td->nonce_pr;\n    t.noncelen = td->noncelen_pr;\n    t.entropycnt = 0;\n    t.noncecnt = 0;\n    if (!TEST_true(RAND_DRBG_instantiate(drbg, td->pers_pr, td->perslen_pr)))\n        failures++;\n    t.entropy = td->entropypr_pr;\n    t.entropylen = td->entropyprlen_pr;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->katlen_pr, 1,\n                                      td->adin_pr, td->adinlen_pr))\n            || !TEST_mem_eq(td->kat_pr, td->katlen_pr, buff, td->katlen_pr))\n        failures++;\n    t.entropy = td->entropyg_pr;\n    t.entropylen = td->entropyglen_pr;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->kat2len_pr, 1,\n                                      td->ading_pr, td->adinglen_pr))\n                || !TEST_mem_eq(td->kat2_pr, td->kat2len_pr,\n                                buff, td->kat2len_pr))\n        failures++;\nerr:\n    uninstantiate(drbg);\n    RAND_DRBG_free(drbg);\n    return failures == 0;\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}']