Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 72187d4

Browse files
committed
[libFuzzer] fix a bug when running a single unit of N bytes with -max_len=M, M<N, caused a buffer overflow
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280098 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 773652b commit 72187d4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/Fuzzer/FuzzerDriver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ static void StartRssThread(Fuzzer *F, size_t RssLimitMb) {
250250
T.detach();
251251
}
252252

253-
int RunOneTest(Fuzzer *F, const char *InputFilePath) {
253+
int RunOneTest(Fuzzer *F, const char *InputFilePath, size_t MaxLen) {
254254
Unit U = FileToVector(InputFilePath);
255-
Unit PreciseSizedU(U);
256-
assert(PreciseSizedU.size() == PreciseSizedU.capacity());
257-
F->RunOne(PreciseSizedU.data(), PreciseSizedU.size());
255+
if (MaxLen && MaxLen < U.size())
256+
U.resize(MaxLen);
257+
F->RunOne(U.data(), U.size());
258258
return 0;
259259
}
260260

@@ -380,7 +380,7 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
380380
auto StartTime = system_clock::now();
381381
Printf("Running: %s\n", Path.c_str());
382382
for (int Iter = 0; Iter < Runs; Iter++)
383-
RunOneTest(&F, Path.c_str());
383+
RunOneTest(&F, Path.c_str(), Options.MaxLen);
384384
auto StopTime = system_clock::now();
385385
auto MS = duration_cast<milliseconds>(StopTime - StartTime).count();
386386
Printf("Executed %s in %zd ms\n", Path.c_str(), (long)MS);

lib/Fuzzer/test/fuzzer-singleinputs.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ RUN: rm -rf %tmp/SINGLE_INPUTS
55
RUN: mkdir -p %tmp/SINGLE_INPUTS
66
RUN: echo aaa > %tmp/SINGLE_INPUTS/aaa
77
RUN: echo bbb > %tmp/SINGLE_INPUTS/bbb
8-
RUN: LLVMFuzzer-SimpleTest %tmp/SINGLE_INPUTS/aaa %tmp/SINGLE_INPUTS/bbb 2>&1 | FileCheck %s --check-prefix=SINGLE_INPUTS
8+
RUN: LLVMFuzzer-SimpleTest %tmp/SINGLE_INPUTS/aaa %tmp/SINGLE_INPUTS/bbb 2>&1 | FileCheck %s --check-prefix=SINGLE_INPUTS
9+
RUN: LLVMFuzzer-SimpleTest -max_len=2 %tmp/SINGLE_INPUTS/aaa %tmp/SINGLE_INPUTS/bbb 2>&1 | FileCheck %s --check-prefix=SINGLE_INPUTS
910
RUN: rm -rf %tmp/SINGLE_INPUTS
1011
SINGLE_INPUTS: LLVMFuzzer-SimpleTest: Running 2 inputs 1 time(s) each.
1112
SINGLE_INPUTS: aaa in

0 commit comments

Comments
 (0)