From 02f3ad81c3dea59e5fde8adaab0bdd265bc94e8e Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Wed, 5 Sep 2018 21:03:43 +0000 Subject: [PATCH] [libfuzzer] Replace memmem with strstr. Summary: Memmem is not available on Windows. Patch By: metzman Reviewers: morehouse Reviewed By: morehouse Subscribers: george.karpenkov, morehouse Differential Revision: https://reviews.llvm.org/D51692 llvm-svn: 341495 --- compiler-rt/test/fuzzer/InitializeTest.cpp | 5 ++--- compiler-rt/test/fuzzer/initialize.test | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler-rt/test/fuzzer/InitializeTest.cpp b/compiler-rt/test/fuzzer/InitializeTest.cpp index a93c2a5..5022c9e 100644 --- a/compiler-rt/test/fuzzer/InitializeTest.cpp +++ b/compiler-rt/test/fuzzer/InitializeTest.cpp @@ -9,7 +9,7 @@ #include #include -static char *argv0; +static char *argv0 = NULL; extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { assert(*argc > 0); @@ -20,8 +20,7 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { assert(argv0); - if (Size == strlen(argv0) && - !memmem(Data, Size, argv0, Size)) { + if (argv0 && Size >= 4 && !memcmp(Data, "fuzz", 4)) { fprintf(stderr, "BINGO %s\n", argv0); exit(1); } diff --git a/compiler-rt/test/fuzzer/initialize.test b/compiler-rt/test/fuzzer/initialize.test index 0ff3796..217743b 100644 --- a/compiler-rt/test/fuzzer/initialize.test +++ b/compiler-rt/test/fuzzer/initialize.test @@ -1,4 +1,4 @@ -# FIXME: Disabled on Windows because memmem is a GNU extension. +# FIXME: Disabled on Windows since LLVMFuzzerInitialize does not yet work. UNSUPPORTED: windows CHECK: BINGO RUN: %cpp_compiler %S/InitializeTest.cpp -o %t-InitializeTest -- 2.7.4