Detect errors in fuzzer initialization

Incomplete initialization typically causes mysterious failures later on,
so let's err out early.

(cherry picked from commit d102c59b96)
This commit is contained in:
Petr Špaček
2022-09-27 10:32:34 +02:00
parent a44ccdbabb
commit 35c5853f8a

View File

@@ -94,10 +94,15 @@ test_all_from(const char *dirname) {
int
main(int argc, char **argv) {
int ret;
char corpusdir[PATH_MAX];
const char *target = strrchr(argv[0], '/');
(void)LLVMFuzzerInitialize(&argc, &argv);
ret = LLVMFuzzerInitialize(&argc, &argv);
if (ret != 0) {
fprintf(stderr, "LLVMFuzzerInitialize failure: %d\n", ret);
return 1;
}
if (argv[1] != NULL && strcmp(argv[1], "-d") == 0) {
debug = true;
@@ -134,7 +139,11 @@ main(int argc, char **argv) {
int ret;
unsigned char buf[64 * 1024];
(void)LLVMFuzzerInitialize(&argc, &argv);
LLVMFuzzerInitialize(&argc, &argv);
if (ret != 0) {
fprintf(stderr, "LLVMFuzzerInitialize failure: %d\n", ret);
return 1;
}
#ifdef __AFL_LOOP
while (__AFL_LOOP(10000)) { /* only works with afl-clang-fast */