From 35c5853f8ac5525b515be9de2dedbdf63dec4614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0pa=C4=8Dek?= Date: Tue, 27 Sep 2022 10:32:34 +0200 Subject: [PATCH] Detect errors in fuzzer initialization Incomplete initialization typically causes mysterious failures later on, so let's err out early. (cherry picked from commit d102c59b96f8859d1f354380d8cf3d7932553956) --- fuzz/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fuzz/main.c b/fuzz/main.c index ddddfe8fe3..4bfc66e1c6 100644 --- a/fuzz/main.c +++ b/fuzz/main.c @@ -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 */