summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/fuzzer/ReloadTest.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2019-04-05 20:17:03 +0000
committerVitaly Buka <vitalybuka@google.com>2019-04-05 20:17:03 +0000
commit3db6ad2bcfc5fb38343cfd7ce6eb56d9415e2b1e (patch)
treeaeaace02175721f5f948547d00487df853312a3b /compiler-rt/test/fuzzer/ReloadTest.cpp
parent883ab235eea79198089319ccbd938ecf47f3c9dd (diff)
downloadbcm5719-llvm-3db6ad2bcfc5fb38343cfd7ce6eb56d9415e2b1e.tar.gz
bcm5719-llvm-3db6ad2bcfc5fb38343cfd7ce6eb56d9415e2b1e.zip
Use binary write mode in WriteToFile function to avoid appended \r characters on Windows
Summary: When using libfuzzer on Windows, in the contents of a crash sample, bytes that can be mistaken for a \n are replaced by a \r\n sequence. As a consequence, crashes are not reproducible. This patch will open files in binary mode to fix this issue. The patch does not affect POSIX systems. Patch by tuktuk Reviewers: kcc, vitalybuka Reviewed By: vitalybuka Subscribers: dexonsmith, jdoerfert, llvm-commits, #sanitizers Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D60008 llvm-svn: 357807
Diffstat (limited to 'compiler-rt/test/fuzzer/ReloadTest.cpp')
-rw-r--r--compiler-rt/test/fuzzer/ReloadTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler-rt/test/fuzzer/ReloadTest.cpp b/compiler-rt/test/fuzzer/ReloadTest.cpp
new file mode 100644
index 00000000000..fb1fef97a30
--- /dev/null
+++ b/compiler-rt/test/fuzzer/ReloadTest.cpp
@@ -0,0 +1,24 @@
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Test that fuzzer we can reload artifacts with any bytes inside.
+#include <algorithm>
+#include <cstdint>
+#include <numeric>
+#include <set>
+#include <stdio.h>
+
+extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size,
+ size_t MaxSize, unsigned int Seed) {
+ std::srand(Seed);
+ std::generate(Data, Data + MaxSize, std::rand);
+ return MaxSize;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size > 5000 && std::set<uint8_t>(Data, Data + Size).size() > 255 &&
+ (uint8_t)std::accumulate(Data, Data + Size, uint8_t(Size)) == 0)
+ __builtin_trap();
+ return 0;
+}
OpenPOWER on IntegriCloud