LLVM
4.0.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
llvm.src
lib
Fuzzer
test
Switch2Test.cpp
Go to the documentation of this file.
1
// This file is distributed under the University of Illinois Open Source
2
// License. See LICENSE.TXT for details.
3
4
// Simple test for a fuzzer. The fuzzer must find the interesting switch value.
5
#include <cstdint>
6
#include <cstdlib>
7
#include <cstdio>
8
#include <cstring>
9
#include <cstddef>
10
11
int
Switch
(
int
a) {
12
switch
(a) {
13
case
100001:
return
1;
14
case
100002:
return
2;
15
case
100003:
return
4;
16
}
17
return
0;
18
}
19
20
extern
"C"
int
LLVMFuzzerTestOneInput
(
const
uint8_t *Data,
size_t
Size) {
21
const
int
N
= 3;
22
if
(Size < N *
sizeof
(
int
))
return
0;
23
int
Res = 0;
24
for
(
int
i
= 0;
i
<
N
;
i
++) {
25
int
X
;
26
memcpy(&X, Data +
i
*
sizeof
(
int
),
sizeof
(
int
));
27
Res +=
Switch
(X);
28
}
29
if
(Res == 5 || Res == 3 || Res == 6 || Res == 7) {
30
fprintf(stderr,
"BINGO; Found the target, exiting; Res=%d\n"
, Res);
31
exit(1);
32
}
33
return
0;
34
}
35
i
size_t i
Definition:
FuzzerTracePC.cpp:312
Switch
int Switch(int a)
Definition:
Switch2Test.cpp:11
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition:
Switch2Test.cpp:20
N
#define N
Generated on Wed Mar 8 2017 17:28:50 for LLVM by
1.8.6