diff options
author | Kostya Serebryany <kcc@google.com> | 2015-08-05 21:32:13 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-08-05 21:32:13 +0000 |
commit | 1ce0035bf0cbbe3709473578a13e00b0731e8140 (patch) | |
tree | e48a35ddbf12d24e3175341308f3b4282aa7f422 | |
parent | 44f5d18587ebeb5c5a27c34ddd53c2cda25d4c9e (diff) | |
download | bcm5719-llvm-1ce0035bf0cbbe3709473578a13e00b0731e8140.tar.gz bcm5719-llvm-1ce0035bf0cbbe3709473578a13e00b0731e8140.zip |
[libFuzzer] add a missing test file
llvm-svn: 244151
-rw-r--r-- | llvm/lib/Fuzzer/test/StrcmpTest.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/StrcmpTest.cpp b/llvm/lib/Fuzzer/test/StrcmpTest.cpp new file mode 100644 index 00000000000..04264fa93fd --- /dev/null +++ b/llvm/lib/Fuzzer/test/StrcmpTest.cpp @@ -0,0 +1,28 @@ +// Break through a series of strcmp. +#include <cstring> +#include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <cassert> + +bool Eq(const uint8_t *Data, size_t Size, const char *Str) { + char Buff[1024]; + size_t Len = strlen(Str); + if (Size < Len) return false; + if (Len >= sizeof(Buff)) return false; + memcpy(Buff, (char*)Data, Len); + Buff[Len] = 0; + int res = strcmp(Buff, Str); + return res == 0; +} + +extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + if (Eq(Data, Size, "AAA") && + Size >= 3 && Eq(Data + 3, Size - 3, "BBBB") && + Size >= 7 && Eq(Data + 7, Size - 7, "CCCCCC") && + Size >= 14 && Data[13] == 42 + ) { + fprintf(stderr, "BINGO\n"); + exit(1); + } +} |