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

Commit 3e014d0

Browse files
committed
[libFuzzer] make SimpleCmpTest a bit simpler to crack and more verbose
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289477 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e4cd1d0 commit 3e014d0

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

lib/Fuzzer/test/SimpleCmpTest.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,40 @@
77
#include <cstring>
88
#include <cstdio>
99

10+
extern int AllLines[];
11+
12+
bool PrintOnce(int Line) {
13+
if (!AllLines[Line])
14+
fprintf(stderr, "Seen line %d\n", Line);
15+
AllLines[Line] = 1;
16+
return true;
17+
}
18+
1019
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
11-
if (Size < 14) return 0;
20+
if (Size != 22) return 0;
1221
uint64_t x = 0;
1322
int64_t y = 0;
14-
int z = 0;
15-
unsigned short a = 0;
16-
memcpy(&x, Data, 8);
17-
memcpy(&y, Data + Size - 8, 8);
18-
memcpy(&z, Data + Size / 2, sizeof(z));
19-
memcpy(&a, Data + Size / 2 + 4, sizeof(a));
23+
int32_t z = 0;
24+
uint16_t a = 0;
25+
memcpy(&x, Data, 8); // 8
26+
memcpy(&y, Data + 8, 8); // 16
27+
memcpy(&z, Data + 16, sizeof(z)); // 20
28+
memcpy(&a, Data + 20, sizeof(a)); // 22
2029

21-
if (x > 1234567890 &&
22-
x < 1234567895 &&
23-
y >= 987654321 &&
24-
y <= 987654325 &&
25-
z < -10000 &&
26-
z >= -10005 &&
27-
z != -10003 &&
28-
a == 4242 &&
30+
if (x > 1234567890 && PrintOnce(__LINE__) &&
31+
x < 1234567895 && PrintOnce(__LINE__) &&
32+
a == 0x4242 && PrintOnce(__LINE__) &&
33+
y >= 987654321 && PrintOnce(__LINE__) &&
34+
y <= 987654325 && PrintOnce(__LINE__) &&
35+
z < -10000 && PrintOnce(__LINE__) &&
36+
z >= -10005 && PrintOnce(__LINE__) &&
37+
z != -10003 && PrintOnce(__LINE__) &&
2938
true) {
3039
fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n",
3140
Size, x, y, z, a);
3241
exit(1);
3342
}
3443
return 0;
3544
}
45+
46+
int AllLines[__LINE__ + 1]; // Must be the last line.

0 commit comments

Comments
 (0)