blob: a2d53ee48dbcece57c767ad111060802bb9e4a13 [file] [log] [blame]
george.karpenkov29efa6d2017-08-21 23:25:50 +00001//===- FuzzerLoop.cpp - Fuzzer's main loop --------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9// Fuzzer's main loop.
10//===----------------------------------------------------------------------===//
11
12#include "FuzzerCorpus.h"
13#include "FuzzerIO.h"
14#include "FuzzerInternal.h"
15#include "FuzzerMutate.h"
16#include "FuzzerRandom.h"
17#include "FuzzerShmem.h"
18#include "FuzzerTracePC.h"
19#include <algorithm>
20#include <cstring>
21#include <memory>
vitalybukab3e5a2c2017-11-01 03:02:59 +000022#include <mutex>
george.karpenkov29efa6d2017-08-21 23:25:50 +000023#include <set>
24
25#if defined(__has_include)
26#if __has_include(<sanitizer / lsan_interface.h>)
27#include <sanitizer/lsan_interface.h>
28#endif
29#endif
30
31#define NO_SANITIZE_MEMORY
32#if defined(__has_feature)
33#if __has_feature(memory_sanitizer)
34#undef NO_SANITIZE_MEMORY
35#define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
36#endif
37#endif
38
39namespace fuzzer {
40static const size_t kMaxUnitSizeToPrint = 256;
41
42thread_local bool Fuzzer::IsMyThread;
43
44SharedMemoryRegion SMR;
45
morehousec6ee8752018-07-17 16:12:00 +000046bool RunningUserCallback = false;
47
george.karpenkov29efa6d2017-08-21 23:25:50 +000048// Only one Fuzzer per process.
49static Fuzzer *F;
50
51// Leak detection is expensive, so we first check if there were more mallocs
52// than frees (using the sanitizer malloc hooks) and only then try to call lsan.
53struct MallocFreeTracer {
54 void Start(int TraceLevel) {
55 this->TraceLevel = TraceLevel;
56 if (TraceLevel)
57 Printf("MallocFreeTracer: START\n");
58 Mallocs = 0;
59 Frees = 0;
60 }
61 // Returns true if there were more mallocs than frees.
62 bool Stop() {
63 if (TraceLevel)
64 Printf("MallocFreeTracer: STOP %zd %zd (%s)\n", Mallocs.load(),
65 Frees.load(), Mallocs == Frees ? "same" : "DIFFERENT");
66 bool Result = Mallocs > Frees;
67 Mallocs = 0;
68 Frees = 0;
69 TraceLevel = 0;
70 return Result;
71 }
72 std::atomic<size_t> Mallocs;
73 std::atomic<size_t> Frees;
74 int TraceLevel = 0;
vitalybukae6504cf2017-11-02 04:12:10 +000075
76 std::recursive_mutex TraceMutex;
77 bool TraceDisabled = false;
george.karpenkov29efa6d2017-08-21 23:25:50 +000078};
79
80static MallocFreeTracer AllocTracer;
81
vitalybukae6504cf2017-11-02 04:12:10 +000082// Locks printing and avoids nested hooks triggered from mallocs/frees in
83// sanitizer.
84class TraceLock {
85public:
86 TraceLock() : Lock(AllocTracer.TraceMutex) {
87 AllocTracer.TraceDisabled = !AllocTracer.TraceDisabled;
88 }
89 ~TraceLock() { AllocTracer.TraceDisabled = !AllocTracer.TraceDisabled; }
90
91 bool IsDisabled() const {
92 // This is already inverted value.
93 return !AllocTracer.TraceDisabled;
94 }
95
96private:
97 std::lock_guard<std::recursive_mutex> Lock;
98};
vitalybukab3e5a2c2017-11-01 03:02:59 +000099
george.karpenkov29efa6d2017-08-21 23:25:50 +0000100ATTRIBUTE_NO_SANITIZE_MEMORY
101void MallocHook(const volatile void *ptr, size_t size) {
102 size_t N = AllocTracer.Mallocs++;
103 F->HandleMalloc(size);
104 if (int TraceLevel = AllocTracer.TraceLevel) {
vitalybukae6504cf2017-11-02 04:12:10 +0000105 TraceLock Lock;
106 if (Lock.IsDisabled())
107 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000108 Printf("MALLOC[%zd] %p %zd\n", N, ptr, size);
109 if (TraceLevel >= 2 && EF)
morehousebd67cc22018-05-08 23:45:05 +0000110 PrintStackTrace();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000111 }
112}
113
114ATTRIBUTE_NO_SANITIZE_MEMORY
115void FreeHook(const volatile void *ptr) {
116 size_t N = AllocTracer.Frees++;
117 if (int TraceLevel = AllocTracer.TraceLevel) {
vitalybukae6504cf2017-11-02 04:12:10 +0000118 TraceLock Lock;
119 if (Lock.IsDisabled())
120 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000121 Printf("FREE[%zd] %p\n", N, ptr);
122 if (TraceLevel >= 2 && EF)
morehousebd67cc22018-05-08 23:45:05 +0000123 PrintStackTrace();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000124 }
125}
126
127// Crash on a single malloc that exceeds the rss limit.
128void Fuzzer::HandleMalloc(size_t Size) {
kcc120e40b2017-12-01 22:12:04 +0000129 if (!Options.MallocLimitMb || (Size >> 20) < (size_t)Options.MallocLimitMb)
george.karpenkov29efa6d2017-08-21 23:25:50 +0000130 return;
131 Printf("==%d== ERROR: libFuzzer: out-of-memory (malloc(%zd))\n", GetPid(),
132 Size);
133 Printf(" To change the out-of-memory limit use -rss_limit_mb=<N>\n\n");
morehousebd67cc22018-05-08 23:45:05 +0000134 PrintStackTrace();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000135 DumpCurrentUnit("oom-");
136 Printf("SUMMARY: libFuzzer: out-of-memory\n");
137 PrintFinalStats();
138 _Exit(Options.ErrorExitCode); // Stop right now.
139}
140
141Fuzzer::Fuzzer(UserCallback CB, InputCorpus &Corpus, MutationDispatcher &MD,
142 FuzzingOptions Options)
143 : CB(CB), Corpus(Corpus), MD(MD), Options(Options) {
144 if (EF->__sanitizer_set_death_callback)
145 EF->__sanitizer_set_death_callback(StaticDeathCallback);
146 assert(!F);
147 F = this;
148 TPC.ResetMaps();
149 IsMyThread = true;
150 if (Options.DetectLeaks && EF->__sanitizer_install_malloc_and_free_hooks)
151 EF->__sanitizer_install_malloc_and_free_hooks(MallocHook, FreeHook);
152 TPC.SetUseCounters(Options.UseCounters);
kcc3850d062018-07-03 22:33:09 +0000153 TPC.SetUseValueProfileMask(Options.UseValueProfile);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000154
155 if (Options.Verbosity)
156 TPC.PrintModuleInfo();
157 if (!Options.OutputCorpus.empty() && Options.ReloadIntervalSec)
158 EpochOfLastReadOfOutputCorpus = GetEpoch(Options.OutputCorpus);
159 MaxInputLen = MaxMutationLen = Options.MaxLen;
160 TmpMaxMutationLen = Max(size_t(4), Corpus.MaxInputSize());
161 AllocateCurrentUnitData();
162 CurrentUnitSize = 0;
163 memset(BaseSha1, 0, sizeof(BaseSha1));
kcc3acbe072018-05-16 23:26:37 +0000164 TPC.SetFocusFunction(Options.FocusFunction);
kcc86e43882018-06-06 01:23:29 +0000165 DFT.Init(Options.DataFlowTrace, Options.FocusFunction);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000166}
167
alekseyshl9f6a9f22017-10-23 23:24:33 +0000168Fuzzer::~Fuzzer() {}
george.karpenkov29efa6d2017-08-21 23:25:50 +0000169
170void Fuzzer::AllocateCurrentUnitData() {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000171 if (CurrentUnitData || MaxInputLen == 0)
172 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000173 CurrentUnitData = new uint8_t[MaxInputLen];
174}
175
176void Fuzzer::StaticDeathCallback() {
177 assert(F);
178 F->DeathCallback();
179}
180
181void Fuzzer::DumpCurrentUnit(const char *Prefix) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000182 if (!CurrentUnitData)
183 return; // Happens when running individual inputs.
morehouse1467b792018-07-09 23:51:08 +0000184 ScopedDisableMsanInterceptorChecks S;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000185 MD.PrintMutationSequence();
186 Printf("; base unit: %s\n", Sha1ToString(BaseSha1).c_str());
187 size_t UnitSize = CurrentUnitSize;
188 if (UnitSize <= kMaxUnitSizeToPrint) {
189 PrintHexArray(CurrentUnitData, UnitSize, "\n");
190 PrintASCII(CurrentUnitData, UnitSize, "\n");
191 }
192 WriteUnitToFileWithPrefix({CurrentUnitData, CurrentUnitData + UnitSize},
193 Prefix);
194}
195
196NO_SANITIZE_MEMORY
197void Fuzzer::DeathCallback() {
198 DumpCurrentUnit("crash-");
199 PrintFinalStats();
200}
201
202void Fuzzer::StaticAlarmCallback() {
203 assert(F);
204 F->AlarmCallback();
205}
206
207void Fuzzer::StaticCrashSignalCallback() {
208 assert(F);
209 F->CrashCallback();
210}
211
212void Fuzzer::StaticExitCallback() {
213 assert(F);
214 F->ExitCallback();
215}
216
217void Fuzzer::StaticInterruptCallback() {
218 assert(F);
219 F->InterruptCallback();
220}
221
kcc1239a992017-11-09 20:30:19 +0000222void Fuzzer::StaticGracefulExitCallback() {
223 assert(F);
224 F->GracefulExitRequested = true;
225 Printf("INFO: signal received, trying to exit gracefully\n");
226}
227
george.karpenkov29efa6d2017-08-21 23:25:50 +0000228void Fuzzer::StaticFileSizeExceedCallback() {
229 Printf("==%lu== ERROR: libFuzzer: file size exceeded\n", GetPid());
230 exit(1);
231}
232
233void Fuzzer::CrashCallback() {
morehousef7b44452018-05-02 02:55:28 +0000234 if (EF->__sanitizer_acquire_crash_state)
235 EF->__sanitizer_acquire_crash_state();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000236 Printf("==%lu== ERROR: libFuzzer: deadly signal\n", GetPid());
morehousebd67cc22018-05-08 23:45:05 +0000237 PrintStackTrace();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000238 Printf("NOTE: libFuzzer has rudimentary signal handlers.\n"
239 " Combine libFuzzer with AddressSanitizer or similar for better "
240 "crash reports.\n");
241 Printf("SUMMARY: libFuzzer: deadly signal\n");
242 DumpCurrentUnit("crash-");
243 PrintFinalStats();
alekseyshl9f6a9f22017-10-23 23:24:33 +0000244 _Exit(Options.ErrorExitCode); // Stop right now.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000245}
246
247void Fuzzer::ExitCallback() {
morehousec6ee8752018-07-17 16:12:00 +0000248 if (!RunningUserCallback)
george.karpenkov29efa6d2017-08-21 23:25:50 +0000249 return; // This exit did not come from the user callback
morehouse5a4566a2018-05-01 21:01:53 +0000250 if (EF->__sanitizer_acquire_crash_state &&
251 !EF->__sanitizer_acquire_crash_state())
252 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000253 Printf("==%lu== ERROR: libFuzzer: fuzz target exited\n", GetPid());
morehousebd67cc22018-05-08 23:45:05 +0000254 PrintStackTrace();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000255 Printf("SUMMARY: libFuzzer: fuzz target exited\n");
256 DumpCurrentUnit("crash-");
257 PrintFinalStats();
258 _Exit(Options.ErrorExitCode);
259}
260
kcc1239a992017-11-09 20:30:19 +0000261void Fuzzer::MaybeExitGracefully() {
262 if (!GracefulExitRequested) return;
263 Printf("==%lu== INFO: libFuzzer: exiting as requested\n", GetPid());
264 PrintFinalStats();
265 _Exit(0);
266}
267
george.karpenkov29efa6d2017-08-21 23:25:50 +0000268void Fuzzer::InterruptCallback() {
269 Printf("==%lu== libFuzzer: run interrupted; exiting\n", GetPid());
270 PrintFinalStats();
alekseyshl9f6a9f22017-10-23 23:24:33 +0000271 _Exit(0); // Stop right now, don't perform any at-exit actions.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000272}
273
274NO_SANITIZE_MEMORY
275void Fuzzer::AlarmCallback() {
276 assert(Options.UnitTimeoutSec > 0);
277 // In Windows Alarm callback is executed by a different thread.
278#if !LIBFUZZER_WINDOWS
alekseyshl9f6a9f22017-10-23 23:24:33 +0000279 if (!InFuzzingThread())
280 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000281#endif
morehousec6ee8752018-07-17 16:12:00 +0000282 if (!RunningUserCallback)
george.karpenkov29efa6d2017-08-21 23:25:50 +0000283 return; // We have not started running units yet.
284 size_t Seconds =
285 duration_cast<seconds>(system_clock::now() - UnitStartTime).count();
286 if (Seconds == 0)
287 return;
288 if (Options.Verbosity >= 2)
289 Printf("AlarmCallback %zd\n", Seconds);
290 if (Seconds >= (size_t)Options.UnitTimeoutSec) {
morehouse5a4566a2018-05-01 21:01:53 +0000291 if (EF->__sanitizer_acquire_crash_state &&
292 !EF->__sanitizer_acquire_crash_state())
293 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000294 Printf("ALARM: working on the last Unit for %zd seconds\n", Seconds);
295 Printf(" and the timeout value is %d (use -timeout=N to change)\n",
296 Options.UnitTimeoutSec);
297 DumpCurrentUnit("timeout-");
298 Printf("==%lu== ERROR: libFuzzer: timeout after %d seconds\n", GetPid(),
299 Seconds);
morehousebd67cc22018-05-08 23:45:05 +0000300 PrintStackTrace();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000301 Printf("SUMMARY: libFuzzer: timeout\n");
302 PrintFinalStats();
303 _Exit(Options.TimeoutExitCode); // Stop right now.
304 }
305}
306
307void Fuzzer::RssLimitCallback() {
morehouse5a4566a2018-05-01 21:01:53 +0000308 if (EF->__sanitizer_acquire_crash_state &&
309 !EF->__sanitizer_acquire_crash_state())
310 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000311 Printf(
312 "==%lu== ERROR: libFuzzer: out-of-memory (used: %zdMb; limit: %zdMb)\n",
313 GetPid(), GetPeakRSSMb(), Options.RssLimitMb);
314 Printf(" To change the out-of-memory limit use -rss_limit_mb=<N>\n\n");
morehousebd67cc22018-05-08 23:45:05 +0000315 PrintMemoryProfile();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000316 DumpCurrentUnit("oom-");
317 Printf("SUMMARY: libFuzzer: out-of-memory\n");
318 PrintFinalStats();
319 _Exit(Options.ErrorExitCode); // Stop right now.
320}
321
322void Fuzzer::PrintStats(const char *Where, const char *End, size_t Units) {
323 size_t ExecPerSec = execPerSec();
324 if (!Options.Verbosity)
325 return;
326 Printf("#%zd\t%s", TotalNumberOfRuns, Where);
327 if (size_t N = TPC.GetTotalPCCoverage())
328 Printf(" cov: %zd", N);
329 if (size_t N = Corpus.NumFeatures())
alekseyshl9f6a9f22017-10-23 23:24:33 +0000330 Printf(" ft: %zd", N);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000331 if (!Corpus.empty()) {
332 Printf(" corp: %zd", Corpus.NumActiveUnits());
333 if (size_t N = Corpus.SizeInBytes()) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000334 if (N < (1 << 14))
george.karpenkov29efa6d2017-08-21 23:25:50 +0000335 Printf("/%zdb", N);
336 else if (N < (1 << 24))
337 Printf("/%zdKb", N >> 10);
338 else
339 Printf("/%zdMb", N >> 20);
340 }
kcc3acbe072018-05-16 23:26:37 +0000341 if (size_t FF = Corpus.NumInputsThatTouchFocusFunction())
342 Printf(" focus: %zd", FF);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000343 }
morehousea6c692c2018-02-22 19:00:17 +0000344 if (TmpMaxMutationLen)
345 Printf(" lim: %zd", TmpMaxMutationLen);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000346 if (Units)
347 Printf(" units: %zd", Units);
348
349 Printf(" exec/s: %zd", ExecPerSec);
350 Printf(" rss: %zdMb", GetPeakRSSMb());
351 Printf("%s", End);
352}
353
354void Fuzzer::PrintFinalStats() {
355 if (Options.PrintCoverage)
356 TPC.PrintCoverage();
dor1sbb933292018-07-16 16:01:31 +0000357 if (Options.PrintUnstableStats)
358 TPC.PrintUnstableStats();
kcca7dd2a92018-05-21 19:47:00 +0000359 if (Options.DumpCoverage)
360 TPC.DumpCoverage();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000361 if (Options.PrintCorpusStats)
362 Corpus.PrintStats();
alekseyshl9f6a9f22017-10-23 23:24:33 +0000363 if (!Options.PrintFinalStats)
364 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000365 size_t ExecPerSec = execPerSec();
366 Printf("stat::number_of_executed_units: %zd\n", TotalNumberOfRuns);
367 Printf("stat::average_exec_per_sec: %zd\n", ExecPerSec);
368 Printf("stat::new_units_added: %zd\n", NumberOfNewUnitsAdded);
369 Printf("stat::slowest_unit_time_sec: %zd\n", TimeOfLongestUnitInSeconds);
370 Printf("stat::peak_rss_mb: %zd\n", GetPeakRSSMb());
371}
372
373void Fuzzer::SetMaxInputLen(size_t MaxInputLen) {
374 assert(this->MaxInputLen == 0); // Can only reset MaxInputLen from 0 to non-0.
375 assert(MaxInputLen);
376 this->MaxInputLen = MaxInputLen;
377 this->MaxMutationLen = MaxInputLen;
378 AllocateCurrentUnitData();
379 Printf("INFO: -max_len is not provided; "
380 "libFuzzer will not generate inputs larger than %zd bytes\n",
381 MaxInputLen);
382}
383
384void Fuzzer::SetMaxMutationLen(size_t MaxMutationLen) {
385 assert(MaxMutationLen && MaxMutationLen <= MaxInputLen);
386 this->MaxMutationLen = MaxMutationLen;
387}
388
389void Fuzzer::CheckExitOnSrcPosOrItem() {
390 if (!Options.ExitOnSrcPos.empty()) {
george.karpenkovfbfa45c2017-08-27 23:20:09 +0000391 static auto *PCsSet = new Set<uintptr_t>;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000392 auto HandlePC = [&](uintptr_t PC) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000393 if (!PCsSet->insert(PC).second)
394 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000395 std::string Descr = DescribePC("%F %L", PC + 1);
396 if (Descr.find(Options.ExitOnSrcPos) != std::string::npos) {
397 Printf("INFO: found line matching '%s', exiting.\n",
398 Options.ExitOnSrcPos.c_str());
399 _Exit(0);
400 }
401 };
402 TPC.ForEachObservedPC(HandlePC);
403 }
404 if (!Options.ExitOnItem.empty()) {
405 if (Corpus.HasUnit(Options.ExitOnItem)) {
406 Printf("INFO: found item with checksum '%s', exiting.\n",
407 Options.ExitOnItem.c_str());
408 _Exit(0);
409 }
410 }
411}
412
413void Fuzzer::RereadOutputCorpus(size_t MaxSize) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000414 if (Options.OutputCorpus.empty() || !Options.ReloadIntervalSec)
415 return;
george.karpenkovfbfa45c2017-08-27 23:20:09 +0000416 Vector<Unit> AdditionalCorpus;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000417 ReadDirToVectorOfUnits(Options.OutputCorpus.c_str(), &AdditionalCorpus,
418 &EpochOfLastReadOfOutputCorpus, MaxSize,
419 /*ExitOnError*/ false);
420 if (Options.Verbosity >= 2)
421 Printf("Reload: read %zd new units.\n", AdditionalCorpus.size());
422 bool Reloaded = false;
423 for (auto &U : AdditionalCorpus) {
424 if (U.size() > MaxSize)
425 U.resize(MaxSize);
426 if (!Corpus.HasUnit(U)) {
427 if (RunOne(U.data(), U.size())) {
428 CheckExitOnSrcPosOrItem();
429 Reloaded = true;
430 }
431 }
432 }
433 if (Reloaded)
434 PrintStats("RELOAD");
435}
436
george.karpenkov29efa6d2017-08-21 23:25:50 +0000437void Fuzzer::PrintPulseAndReportSlowInput(const uint8_t *Data, size_t Size) {
438 auto TimeOfUnit =
439 duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
440 if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)) &&
441 secondsSinceProcessStartUp() >= 2)
442 PrintStats("pulse ");
443 if (TimeOfUnit > TimeOfLongestUnitInSeconds * 1.1 &&
444 TimeOfUnit >= Options.ReportSlowUnits) {
445 TimeOfLongestUnitInSeconds = TimeOfUnit;
446 Printf("Slowest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
447 WriteUnitToFileWithPrefix({Data, Data + Size}, "slow-unit-");
448 }
449}
450
dor1sbb933292018-07-16 16:01:31 +0000451void Fuzzer::CheckForUnstableCounters(const uint8_t *Data, size_t Size) {
452 auto CBSetupAndRun = [&]() {
453 ScopedEnableMsanInterceptorChecks S;
454 UnitStartTime = system_clock::now();
455 TPC.ResetMaps();
morehousec6ee8752018-07-17 16:12:00 +0000456 RunningUserCallback = true;
dor1sbb933292018-07-16 16:01:31 +0000457 CB(Data, Size);
morehousec6ee8752018-07-17 16:12:00 +0000458 RunningUserCallback = false;
dor1sbb933292018-07-16 16:01:31 +0000459 UnitStopTime = system_clock::now();
460 };
461
462 // Copy original run counters into our unstable counters
463 TPC.InitializeUnstableCounters();
464
465 // First Rerun
466 CBSetupAndRun();
467 TPC.UpdateUnstableCounters();
468
469 // Second Rerun
470 CBSetupAndRun();
471 TPC.UpdateUnstableCounters();
472}
473
george.karpenkov29efa6d2017-08-21 23:25:50 +0000474bool Fuzzer::RunOne(const uint8_t *Data, size_t Size, bool MayDeleteFile,
kccb6836be2017-12-01 19:18:38 +0000475 InputInfo *II, bool *FoundUniqFeatures) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000476 if (!Size)
477 return false;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000478
479 ExecuteCallback(Data, Size);
480
481 UniqFeatureSetTmp.clear();
482 size_t FoundUniqFeaturesOfII = 0;
483 size_t NumUpdatesBefore = Corpus.NumFeatureUpdates();
484 TPC.CollectFeatures([&](size_t Feature) {
485 if (Corpus.AddFeature(Feature, Size, Options.Shrink))
486 UniqFeatureSetTmp.push_back(Feature);
487 if (Options.ReduceInputs && II)
488 if (std::binary_search(II->UniqFeatureSet.begin(),
489 II->UniqFeatureSet.end(), Feature))
490 FoundUniqFeaturesOfII++;
491 });
kccb6836be2017-12-01 19:18:38 +0000492 if (FoundUniqFeatures)
493 *FoundUniqFeatures = FoundUniqFeaturesOfII;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000494 PrintPulseAndReportSlowInput(Data, Size);
495 size_t NumNewFeatures = Corpus.NumFeatureUpdates() - NumUpdatesBefore;
dor1sbb933292018-07-16 16:01:31 +0000496
497 // If print_unstable_stats, execute the same input two more times to detect
498 // unstable edges.
499 if (NumNewFeatures && Options.PrintUnstableStats)
500 CheckForUnstableCounters(Data, Size);
501
george.karpenkov29efa6d2017-08-21 23:25:50 +0000502 if (NumNewFeatures) {
503 TPC.UpdateObservedPCs();
504 Corpus.AddToCorpus({Data, Data + Size}, NumNewFeatures, MayDeleteFile,
kcc3acbe072018-05-16 23:26:37 +0000505 TPC.ObservedFocusFunction(),
kccadf188b2018-06-07 01:40:20 +0000506 UniqFeatureSetTmp, DFT);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000507 return true;
508 }
509 if (II && FoundUniqFeaturesOfII &&
kccadf188b2018-06-07 01:40:20 +0000510 II->DataFlowTraceForFocusFunction.empty() &&
george.karpenkov29efa6d2017-08-21 23:25:50 +0000511 FoundUniqFeaturesOfII == II->UniqFeatureSet.size() &&
512 II->U.size() > Size) {
513 Corpus.Replace(II, {Data, Data + Size});
514 return true;
515 }
516 return false;
517}
518
519size_t Fuzzer::GetCurrentUnitInFuzzingThead(const uint8_t **Data) const {
520 assert(InFuzzingThread());
521 *Data = CurrentUnitData;
522 return CurrentUnitSize;
523}
524
525void Fuzzer::CrashOnOverwrittenData() {
526 Printf("==%d== ERROR: libFuzzer: fuzz target overwrites it's const input\n",
527 GetPid());
528 DumpCurrentUnit("crash-");
529 Printf("SUMMARY: libFuzzer: out-of-memory\n");
530 _Exit(Options.ErrorExitCode); // Stop right now.
531}
532
533// Compare two arrays, but not all bytes if the arrays are large.
534static bool LooseMemeq(const uint8_t *A, const uint8_t *B, size_t Size) {
535 const size_t Limit = 64;
536 if (Size <= 64)
537 return !memcmp(A, B, Size);
538 // Compare first and last Limit/2 bytes.
539 return !memcmp(A, B, Limit / 2) &&
540 !memcmp(A + Size - Limit / 2, B + Size - Limit / 2, Limit / 2);
541}
542
543void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) {
544 TPC.RecordInitialStack();
545 TotalNumberOfRuns++;
546 assert(InFuzzingThread());
547 if (SMR.IsClient())
548 SMR.WriteByteArray(Data, Size);
549 // We copy the contents of Unit into a separate heap buffer
550 // so that we reliably find buffer overflows in it.
551 uint8_t *DataCopy = new uint8_t[Size];
552 memcpy(DataCopy, Data, Size);
morehouse1467b792018-07-09 23:51:08 +0000553 if (EF->__msan_unpoison)
554 EF->__msan_unpoison(DataCopy, Size);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000555 if (CurrentUnitData && CurrentUnitData != Data)
556 memcpy(CurrentUnitData, Data, Size);
557 CurrentUnitSize = Size;
morehouse1467b792018-07-09 23:51:08 +0000558 {
559 ScopedEnableMsanInterceptorChecks S;
560 AllocTracer.Start(Options.TraceMalloc);
561 UnitStartTime = system_clock::now();
562 TPC.ResetMaps();
morehousec6ee8752018-07-17 16:12:00 +0000563 RunningUserCallback = true;
morehouse1467b792018-07-09 23:51:08 +0000564 int Res = CB(DataCopy, Size);
morehousec6ee8752018-07-17 16:12:00 +0000565 RunningUserCallback = false;
morehouse1467b792018-07-09 23:51:08 +0000566 UnitStopTime = system_clock::now();
567 (void)Res;
568 assert(Res == 0);
569 HasMoreMallocsThanFrees = AllocTracer.Stop();
570 }
george.karpenkov29efa6d2017-08-21 23:25:50 +0000571 if (!LooseMemeq(DataCopy, Data, Size))
572 CrashOnOverwrittenData();
573 CurrentUnitSize = 0;
574 delete[] DataCopy;
575}
576
577void Fuzzer::WriteToOutputCorpus(const Unit &U) {
578 if (Options.OnlyASCII)
579 assert(IsASCII(U));
580 if (Options.OutputCorpus.empty())
581 return;
582 std::string Path = DirPlusFile(Options.OutputCorpus, Hash(U));
583 WriteToFile(U, Path);
584 if (Options.Verbosity >= 2)
585 Printf("Written %zd bytes to %s\n", U.size(), Path.c_str());
586}
587
588void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) {
589 if (!Options.SaveArtifacts)
590 return;
591 std::string Path = Options.ArtifactPrefix + Prefix + Hash(U);
592 if (!Options.ExactArtifactPath.empty())
593 Path = Options.ExactArtifactPath; // Overrides ArtifactPrefix.
594 WriteToFile(U, Path);
595 Printf("artifact_prefix='%s'; Test unit written to %s\n",
596 Options.ArtifactPrefix.c_str(), Path.c_str());
597 if (U.size() <= kMaxUnitSizeToPrint)
598 Printf("Base64: %s\n", Base64(U).c_str());
599}
600
601void Fuzzer::PrintStatusForNewUnit(const Unit &U, const char *Text) {
602 if (!Options.PrintNEW)
603 return;
604 PrintStats(Text, "");
605 if (Options.Verbosity) {
606 Printf(" L: %zd/%zd ", U.size(), Corpus.MaxInputSize());
607 MD.PrintMutationSequence();
608 Printf("\n");
609 }
610}
611
612void Fuzzer::ReportNewCoverage(InputInfo *II, const Unit &U) {
613 II->NumSuccessfullMutations++;
614 MD.RecordSuccessfulMutationSequence();
alekseyshl9f6a9f22017-10-23 23:24:33 +0000615 PrintStatusForNewUnit(U, II->Reduced ? "REDUCE" : "NEW ");
george.karpenkov29efa6d2017-08-21 23:25:50 +0000616 WriteToOutputCorpus(U);
617 NumberOfNewUnitsAdded++;
alekseyshl9f6a9f22017-10-23 23:24:33 +0000618 CheckExitOnSrcPosOrItem(); // Check only after the unit is saved to corpus.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000619 LastCorpusUpdateRun = TotalNumberOfRuns;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000620}
621
622// Tries detecting a memory leak on the particular input that we have just
623// executed before calling this function.
624void Fuzzer::TryDetectingAMemoryLeak(const uint8_t *Data, size_t Size,
625 bool DuringInitialCorpusExecution) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000626 if (!HasMoreMallocsThanFrees)
627 return; // mallocs==frees, a leak is unlikely.
628 if (!Options.DetectLeaks)
629 return;
dor1s38279cb2017-09-12 02:01:54 +0000630 if (!DuringInitialCorpusExecution &&
alekseyshl9f6a9f22017-10-23 23:24:33 +0000631 TotalNumberOfRuns >= Options.MaxNumberOfRuns)
632 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000633 if (!&(EF->__lsan_enable) || !&(EF->__lsan_disable) ||
634 !(EF->__lsan_do_recoverable_leak_check))
alekseyshl9f6a9f22017-10-23 23:24:33 +0000635 return; // No lsan.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000636 // Run the target once again, but with lsan disabled so that if there is
637 // a real leak we do not report it twice.
638 EF->__lsan_disable();
639 ExecuteCallback(Data, Size);
640 EF->__lsan_enable();
alekseyshl9f6a9f22017-10-23 23:24:33 +0000641 if (!HasMoreMallocsThanFrees)
642 return; // a leak is unlikely.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000643 if (NumberOfLeakDetectionAttempts++ > 1000) {
644 Options.DetectLeaks = false;
645 Printf("INFO: libFuzzer disabled leak detection after every mutation.\n"
646 " Most likely the target function accumulates allocated\n"
647 " memory in a global state w/o actually leaking it.\n"
648 " You may try running this binary with -trace_malloc=[12]"
649 " to get a trace of mallocs and frees.\n"
650 " If LeakSanitizer is enabled in this process it will still\n"
651 " run on the process shutdown.\n");
652 return;
653 }
654 // Now perform the actual lsan pass. This is expensive and we must ensure
655 // we don't call it too often.
656 if (EF->__lsan_do_recoverable_leak_check()) { // Leak is found, report it.
657 if (DuringInitialCorpusExecution)
658 Printf("\nINFO: a leak has been found in the initial corpus.\n\n");
659 Printf("INFO: to ignore leaks on libFuzzer side use -detect_leaks=0.\n\n");
660 CurrentUnitSize = Size;
661 DumpCurrentUnit("leak-");
662 PrintFinalStats();
alekseyshl9f6a9f22017-10-23 23:24:33 +0000663 _Exit(Options.ErrorExitCode); // not exit() to disable lsan further on.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000664 }
665}
666
667void Fuzzer::MutateAndTestOne() {
668 MD.StartMutationSequence();
669
670 auto &II = Corpus.ChooseUnitToMutate(MD.GetRand());
671 const auto &U = II.U;
672 memcpy(BaseSha1, II.Sha1, sizeof(BaseSha1));
673 assert(CurrentUnitData);
674 size_t Size = U.size();
675 assert(Size <= MaxInputLen && "Oversized Unit");
676 memcpy(CurrentUnitData, U.data(), Size);
677
678 assert(MaxMutationLen > 0);
679
680 size_t CurrentMaxMutationLen =
681 Min(MaxMutationLen, Max(U.size(), TmpMaxMutationLen));
682 assert(CurrentMaxMutationLen > 0);
683
684 for (int i = 0; i < Options.MutateDepth; i++) {
685 if (TotalNumberOfRuns >= Options.MaxNumberOfRuns)
686 break;
kcc1239a992017-11-09 20:30:19 +0000687 MaybeExitGracefully();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000688 size_t NewSize = 0;
689 NewSize = MD.Mutate(CurrentUnitData, Size, CurrentMaxMutationLen);
690 assert(NewSize > 0 && "Mutator returned empty unit");
alekseyshld995b552017-10-23 22:04:30 +0000691 assert(NewSize <= CurrentMaxMutationLen && "Mutator return oversized unit");
george.karpenkov29efa6d2017-08-21 23:25:50 +0000692 Size = NewSize;
693 II.NumExecutedMutations++;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000694
kccb6836be2017-12-01 19:18:38 +0000695 bool FoundUniqFeatures = false;
696 bool NewCov = RunOne(CurrentUnitData, Size, /*MayDeleteFile=*/true, &II,
697 &FoundUniqFeatures);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000698 TryDetectingAMemoryLeak(CurrentUnitData, Size,
699 /*DuringInitialCorpusExecution*/ false);
kccb6836be2017-12-01 19:18:38 +0000700 if (NewCov) {
morehouse553f00b2017-11-09 20:44:08 +0000701 ReportNewCoverage(&II, {CurrentUnitData, CurrentUnitData + Size});
kccb6836be2017-12-01 19:18:38 +0000702 break; // We will mutate this input more in the next rounds.
703 }
704 if (Options.ReduceDepth && !FoundUniqFeatures)
dor1se6729cb2018-07-16 15:15:34 +0000705 break;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000706 }
707}
708
alekseyshld995b552017-10-23 22:04:30 +0000709void Fuzzer::PurgeAllocator() {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000710 if (Options.PurgeAllocatorIntervalSec < 0 || !EF->__sanitizer_purge_allocator)
alekseyshld995b552017-10-23 22:04:30 +0000711 return;
alekseyshld995b552017-10-23 22:04:30 +0000712 if (duration_cast<seconds>(system_clock::now() -
alekseyshl9f6a9f22017-10-23 23:24:33 +0000713 LastAllocatorPurgeAttemptTime)
714 .count() < Options.PurgeAllocatorIntervalSec)
alekseyshld995b552017-10-23 22:04:30 +0000715 return;
alekseyshld995b552017-10-23 22:04:30 +0000716
717 if (Options.RssLimitMb <= 0 ||
alekseyshl9f6a9f22017-10-23 23:24:33 +0000718 GetPeakRSSMb() > static_cast<size_t>(Options.RssLimitMb) / 2)
alekseyshld995b552017-10-23 22:04:30 +0000719 EF->__sanitizer_purge_allocator();
alekseyshld995b552017-10-23 22:04:30 +0000720
721 LastAllocatorPurgeAttemptTime = system_clock::now();
722}
723
kcc2e93b3f2017-08-29 02:05:01 +0000724void Fuzzer::ReadAndExecuteSeedCorpora(const Vector<std::string> &CorpusDirs) {
725 const size_t kMaxSaneLen = 1 << 20;
726 const size_t kMinDefaultLen = 4096;
kccdc00cd32017-08-29 20:51:24 +0000727 Vector<SizedFile> SizedFiles;
728 size_t MaxSize = 0;
729 size_t MinSize = -1;
730 size_t TotalSize = 0;
kcc7f5f2222017-09-12 21:58:07 +0000731 size_t LastNumFiles = 0;
kccdc00cd32017-08-29 20:51:24 +0000732 for (auto &Dir : CorpusDirs) {
kcc7f5f2222017-09-12 21:58:07 +0000733 GetSizedFilesFromDir(Dir, &SizedFiles);
734 Printf("INFO: % 8zd files found in %s\n", SizedFiles.size() - LastNumFiles,
735 Dir.c_str());
736 LastNumFiles = SizedFiles.size();
737 }
738 for (auto &File : SizedFiles) {
739 MaxSize = Max(File.Size, MaxSize);
740 MinSize = Min(File.Size, MinSize);
741 TotalSize += File.Size;
kcc2e93b3f2017-08-29 02:05:01 +0000742 }
kccdc00cd32017-08-29 20:51:24 +0000743 if (Options.MaxLen == 0)
744 SetMaxInputLen(std::min(std::max(kMinDefaultLen, MaxSize), kMaxSaneLen));
745 assert(MaxInputLen > 0);
746
kcc2cd9f092017-10-13 01:12:23 +0000747 // Test the callback with empty input and never try it again.
748 uint8_t dummy = 0;
749 ExecuteCallback(&dummy, 0);
750
kccdc00cd32017-08-29 20:51:24 +0000751 if (SizedFiles.empty()) {
752 Printf("INFO: A corpus is not provided, starting from an empty corpus\n");
753 Unit U({'\n'}); // Valid ASCII input.
754 RunOne(U.data(), U.size());
755 } else {
756 Printf("INFO: seed corpus: files: %zd min: %zdb max: %zdb total: %zdb"
757 " rss: %zdMb\n",
758 SizedFiles.size(), MinSize, MaxSize, TotalSize, GetPeakRSSMb());
759 if (Options.ShuffleAtStartUp)
760 std::shuffle(SizedFiles.begin(), SizedFiles.end(), MD.GetRand());
761
kcc7f5f2222017-09-12 21:58:07 +0000762 if (Options.PreferSmall) {
763 std::stable_sort(SizedFiles.begin(), SizedFiles.end());
764 assert(SizedFiles.front().Size <= SizedFiles.back().Size);
765 }
kccdc00cd32017-08-29 20:51:24 +0000766
767 // Load and execute inputs one by one.
768 for (auto &SF : SizedFiles) {
kccae85e292017-08-31 19:17:15 +0000769 auto U = FileToVector(SF.File, MaxInputLen, /*ExitOnError=*/false);
kccdc00cd32017-08-29 20:51:24 +0000770 assert(U.size() <= MaxInputLen);
771 RunOne(U.data(), U.size());
772 CheckExitOnSrcPosOrItem();
773 TryDetectingAMemoryLeak(U.data(), U.size(),
774 /*DuringInitialCorpusExecution*/ true);
775 }
kcc2e93b3f2017-08-29 02:05:01 +0000776 }
777
kccdc00cd32017-08-29 20:51:24 +0000778 PrintStats("INITED");
kcc3acbe072018-05-16 23:26:37 +0000779 if (!Options.FocusFunction.empty())
780 Printf("INFO: %zd/%zd inputs touch the focus function\n",
781 Corpus.NumInputsThatTouchFocusFunction(), Corpus.size());
kccadf188b2018-06-07 01:40:20 +0000782 if (!Options.DataFlowTrace.empty())
783 Printf("INFO: %zd/%zd inputs have the Data Flow Trace\n",
784 Corpus.NumInputsWithDataFlowTrace(), Corpus.size());
kcc3acbe072018-05-16 23:26:37 +0000785
dor1s770a9bc2018-05-23 19:42:30 +0000786 if (Corpus.empty() && Options.MaxNumberOfRuns) {
kccdc00cd32017-08-29 20:51:24 +0000787 Printf("ERROR: no interesting inputs were found. "
788 "Is the code instrumented for coverage? Exiting.\n");
789 exit(1);
kcc2e93b3f2017-08-29 02:05:01 +0000790 }
kcc2e93b3f2017-08-29 02:05:01 +0000791}
792
793void Fuzzer::Loop(const Vector<std::string> &CorpusDirs) {
794 ReadAndExecuteSeedCorpora(CorpusDirs);
kccadf188b2018-06-07 01:40:20 +0000795 DFT.Clear(); // No need for DFT any more.
george.karpenkov29efa6d2017-08-21 23:25:50 +0000796 TPC.SetPrintNewPCs(Options.PrintNewCovPcs);
kcc00da6482017-08-25 20:09:25 +0000797 TPC.SetPrintNewFuncs(Options.PrintNewCovFuncs);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000798 system_clock::time_point LastCorpusReload = system_clock::now();
799 if (Options.DoCrossOver)
800 MD.SetCorpus(&Corpus);
801 while (true) {
802 auto Now = system_clock::now();
803 if (duration_cast<seconds>(Now - LastCorpusReload).count() >=
804 Options.ReloadIntervalSec) {
805 RereadOutputCorpus(MaxInputLen);
806 LastCorpusReload = system_clock::now();
807 }
808 if (TotalNumberOfRuns >= Options.MaxNumberOfRuns)
809 break;
alekseyshl9f6a9f22017-10-23 23:24:33 +0000810 if (TimedOut())
811 break;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000812
813 // Update TmpMaxMutationLen
morehouse8c42ada2018-02-13 20:52:15 +0000814 if (Options.LenControl) {
george.karpenkov29efa6d2017-08-21 23:25:50 +0000815 if (TmpMaxMutationLen < MaxMutationLen &&
kcce29d7e32017-12-12 23:11:28 +0000816 TotalNumberOfRuns - LastCorpusUpdateRun >
morehouse8c42ada2018-02-13 20:52:15 +0000817 Options.LenControl * Log(TmpMaxMutationLen)) {
george.karpenkov29efa6d2017-08-21 23:25:50 +0000818 TmpMaxMutationLen =
kcce29d7e32017-12-12 23:11:28 +0000819 Min(MaxMutationLen, TmpMaxMutationLen + Log(TmpMaxMutationLen));
kcce29d7e32017-12-12 23:11:28 +0000820 LastCorpusUpdateRun = TotalNumberOfRuns;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000821 }
822 } else {
823 TmpMaxMutationLen = MaxMutationLen;
824 }
825
826 // Perform several mutations and runs.
827 MutateAndTestOne();
alekseyshld995b552017-10-23 22:04:30 +0000828
829 PurgeAllocator();
george.karpenkov29efa6d2017-08-21 23:25:50 +0000830 }
831
832 PrintStats("DONE ", "\n");
833 MD.PrintRecommendedDictionary();
834}
835
836void Fuzzer::MinimizeCrashLoop(const Unit &U) {
alekseyshl9f6a9f22017-10-23 23:24:33 +0000837 if (U.size() <= 1)
838 return;
george.karpenkov29efa6d2017-08-21 23:25:50 +0000839 while (!TimedOut() && TotalNumberOfRuns < Options.MaxNumberOfRuns) {
840 MD.StartMutationSequence();
841 memcpy(CurrentUnitData, U.data(), U.size());
842 for (int i = 0; i < Options.MutateDepth; i++) {
843 size_t NewSize = MD.Mutate(CurrentUnitData, U.size(), MaxMutationLen);
844 assert(NewSize > 0 && NewSize <= MaxMutationLen);
845 ExecuteCallback(CurrentUnitData, NewSize);
846 PrintPulseAndReportSlowInput(CurrentUnitData, NewSize);
847 TryDetectingAMemoryLeak(CurrentUnitData, NewSize,
848 /*DuringInitialCorpusExecution*/ false);
849 }
850 }
851}
852
853void Fuzzer::AnnounceOutput(const uint8_t *Data, size_t Size) {
854 if (SMR.IsServer()) {
855 SMR.WriteByteArray(Data, Size);
856 } else if (SMR.IsClient()) {
857 SMR.PostClient();
858 SMR.WaitServer();
859 size_t OtherSize = SMR.ReadByteArraySize();
860 uint8_t *OtherData = SMR.GetByteArray();
861 if (Size != OtherSize || memcmp(Data, OtherData, Size) != 0) {
862 size_t i = 0;
863 for (i = 0; i < Min(Size, OtherSize); i++)
864 if (Data[i] != OtherData[i])
865 break;
866 Printf("==%lu== ERROR: libFuzzer: equivalence-mismatch. Sizes: %zd %zd; "
alekseyshl9f6a9f22017-10-23 23:24:33 +0000867 "offset %zd\n",
868 GetPid(), Size, OtherSize, i);
george.karpenkov29efa6d2017-08-21 23:25:50 +0000869 DumpCurrentUnit("mismatch-");
870 Printf("SUMMARY: libFuzzer: equivalence-mismatch\n");
871 PrintFinalStats();
872 _Exit(Options.ErrorExitCode);
873 }
874 }
875}
876
877} // namespace fuzzer
878
879extern "C" {
880
phosek966475e2018-01-17 20:39:14 +0000881__attribute__((visibility("default"))) size_t
882LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize) {
george.karpenkov29efa6d2017-08-21 23:25:50 +0000883 assert(fuzzer::F);
884 return fuzzer::F->GetMD().DefaultMutate(Data, Size, MaxSize);
885}
886
887// Experimental
phosek966475e2018-01-17 20:39:14 +0000888__attribute__((visibility("default"))) void
889LLVMFuzzerAnnounceOutput(const uint8_t *Data, size_t Size) {
george.karpenkov29efa6d2017-08-21 23:25:50 +0000890 assert(fuzzer::F);
891 fuzzer::F->AnnounceOutput(Data, Size);
892}
alekseyshl9f6a9f22017-10-23 23:24:33 +0000893} // extern "C"