[PATCH] D30682: [fuzzer] Don't crash if LLVMFuzzerMutate was called by CustomCrossOver
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 7 00:56:48 PST 2017
vitalybuka updated this revision to Diff 90811.
vitalybuka added a comment.
Includes
https://reviews.llvm.org/D30682
Files:
lib/Fuzzer/FuzzerMutate.cpp
lib/Fuzzer/FuzzerMutate.h
lib/Fuzzer/test/CMakeLists.txt
lib/Fuzzer/test/CustomCrossOverAndMutateTest.cpp
lib/Fuzzer/test/fuzzer-customcrossoverandmutate.test
Index: lib/Fuzzer/test/fuzzer-customcrossoverandmutate.test
===================================================================
--- /dev/null
+++ lib/Fuzzer/test/fuzzer-customcrossoverandmutate.test
@@ -0,0 +1 @@
+RUN: LLVMFuzzer-CustomCrossOverAndMutateTest -seed=1 -use_memcmp=0 -runs=100000
Index: lib/Fuzzer/test/CustomCrossOverAndMutateTest.cpp
===================================================================
--- /dev/null
+++ lib/Fuzzer/test/CustomCrossOverAndMutateTest.cpp
@@ -0,0 +1,33 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+// Test that libFuzzer does not crash when LLVMFuzzerMutate called from
+// LLVMFuzzerCustomCrossOver.
+#include <cstddef>
+#include <cstdint>
+#include <cstdlib>
+#include <string>
+#include <string.h>
+#include <vector>
+
+#include "FuzzerInterface.h"
+
+static volatile int sink;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ std::string Str(reinterpret_cast<const char *>(Data), Size);
+ if (Size && Data[0] == '0')
+ sink++;
+ return 0;
+}
+
+extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
+ const uint8_t *Data2, size_t Size2,
+ uint8_t *Out, size_t MaxOutSize,
+ unsigned int Seed) {
+ std::vector<uint8_t> Buffer(MaxOutSize * 10);
+ LLVMFuzzerMutate(Buffer.data(), Buffer.size(), Buffer.size());
+ size_t Size = std::min<size_t>(Size1, MaxOutSize);
+ memcpy(Out, Data1, Size);
+ return Size;
+}
Index: lib/Fuzzer/test/CMakeLists.txt
===================================================================
--- lib/Fuzzer/test/CMakeLists.txt
+++ lib/Fuzzer/test/CMakeLists.txt
@@ -80,6 +80,7 @@
BufferOverflowOnInput
CallerCalleeTest
CounterTest
+ CustomCrossOverAndMutateTest
CustomCrossOverTest
CustomMutatorTest
CxxStringEqTest
Index: lib/Fuzzer/FuzzerMutate.h
===================================================================
--- lib/Fuzzer/FuzzerMutate.h
+++ lib/Fuzzer/FuzzerMutate.h
@@ -143,6 +143,9 @@
const InputCorpus *Corpus = nullptr;
std::vector<uint8_t> MutateInPlaceHere;
+ // Custom CrossOver needs own buffer as implementation can call
+ // LLVMFuzzerMutate which can resize MutateInPlaceHere.
+ std::vector<uint8_t> CustomCrossOverInPlaceHere;
std::vector<Mutator> Mutators;
std::vector<Mutator> DefaultMutators;
Index: lib/Fuzzer/FuzzerMutate.cpp
===================================================================
--- lib/Fuzzer/FuzzerMutate.cpp
+++ lib/Fuzzer/FuzzerMutate.cpp
@@ -81,8 +81,8 @@
const Unit &Other = (*Corpus)[Idx];
if (Other.empty())
return 0;
- MutateInPlaceHere.resize(MaxSize);
- auto &U = MutateInPlaceHere;
+ CustomCrossOverInPlaceHere.resize(MaxSize);
+ auto &U = CustomCrossOverInPlaceHere;
size_t NewSize = EF->LLVMFuzzerCustomCrossOver(
Data, Size, Other.data(), Other.size(), U.data(), U.size(), Rand.Rand());
if (!NewSize)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30682.90811.patch
Type: text/x-patch
Size: 3068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170307/3225a9f6/attachment.bin>
More information about the llvm-commits
mailing list