Skip to content

Commit 68f40c5

Browse files
committed
Add more examples
1 parent f7437dc commit 68f40c5

File tree

30 files changed

+213
-24
lines changed

30 files changed

+213
-24
lines changed

examples/c-ares/custom.rule

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
func_include ares_*
2+
3+
// func_exclude ares_expand_name,ares_getaddrinfo,ares_gethostbyaddr
4+
// func_exclude ares_fds,ares_dup
5+
// func_exclude ares_library_init_mem

examples/c-ares/hopper.config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Configurations for hopper fuzzer
2+
3+
# Full path for header file
4+
TEST_HEADER=/data/workspace/fuzzing_bench/c-ares/src/include/ares.h
5+
6+
# Full path to shared library
7+
TEST_LIBRARY=/data/workspace/fuzzing_bench/c-ares/build/hopper_build/install/lib/libcares.so
8+
9+
# Output directory
10+
OUT_DIR=output
11+
12+
# Set map size
13+
HOPPER_MAP_SIZE_POW2=18
14+
15+
# Set the header include path
16+
HOPPER_INCLUDE_SEARCH_PATH=/data/workspace/fuzzing_bench/c-ares/src/include/
17+
18+
# Disable generate calls that failed to be invoked
19+
DISABLE_GEN_FAIL=1
20+
21+
# Set seeds
22+
HOPPER_SEED_DIR=/data/workspace/fuzzing_bench/c-ares/src/test/fuzzinput
23+

examples/lcms2/hopper.config

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ OUT_DIR=output
1414
# Custom rule for invoking API functions
1515
CUSTOM_RULES=custom.rule
1616

17-
# set map size for branch counting
17+
# Set map size for branch counting
1818
HOPPER_MAP_SIZE_POW2=18
19-
# disable API-sensitive
19+
20+
# Disable API-sensitive
2021
HOPPER_API_INSENSITIVE_COV=1
21-
# disable fast loop for execution
22+
23+
# Disable fast loop for execution
2224
HOPPER_FAST_EXECUTE_LOOP=1
2325

24-
# set seeds for hopper
25-
# HOPPER_SEED_DIR=seeds
26+
# Set seeds for hopper
27+
# HOPPER_SEED_DIR=seeds

examples/libaom/av1_dev_fuzzer.dict

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# from aom's source code.
2+
3+
# IVF Signature + version (bytes 0-5)
4+
kw1="DKIF\x00\x00"
5+
6+
# AV1 codec fourCC (bytes 8-11)
7+
kw2="AV01"
8+

examples/libaom/custom.rule

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func_include aom_*
2+
// func_include aom_codec_decode,aom_codec_dec_init_ver,aom_codec_av1_dx
3+
// func_key aom_codec_decode,aom_codec_get_frame
4+
func_exclude aom_img_metadata_free,aom_img_free,aom_codec_control,aom_img_alloc,aom_img_alloc_with_border

examples/libaom/hopper.config

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Configurations for hopper fuzzer
2+
3+
# Full path for header file
4+
TEST_HEADER=aom_all.h
5+
6+
# Full path to shared library
7+
TEST_LIBRARY=/data/workspace/fuzzing_bench/libaom/build/hopper_build/libaom.so
8+
9+
# Output directory
10+
OUT_DIR=output
11+
12+
# Set map size for branch counting
13+
HOPPER_MAP_SIZE_POW2=18
14+
15+
# Set dictionary for bytes
16+
HOPPER_DICT=./av1_dec_fuzzer.dict
17+
18+
# Set the header include path
19+
HOPPER_INCLUDE_SEARCH_PATH=/data/workspace/fuzzing_bench/libaom/src

examples/libmagic/custom.rule

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target_include magic_*
2+
# You need to set it the correct path
3+
func magic_load[$1] = "/data/workspace/fuzzing_bench/libmagic/build/hopper_build/magic/magic.mgc"

examples/libmagic/hopper.config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Configurations for hopper fuzzer
2+
3+
# Full path for header file
4+
TEST_HEADER=/data/workspace/fuzzing_bench/libmagic/build/hopper_build/src/magic.h
5+
6+
# Full path to shared library
7+
TEST_LIBRARY=/data/workspace/fuzzing_bench/libmagic/build/hopper_build/src/.libs/libmagic.so
8+
9+
# Output directory
10+
OUT_DIR=output
11+
12+
# set map size for branch counting
13+
HOPPER_MAP_SIZE_POW2=18
14+
15+
# Set seeds
16+
# HOPPER_SEED_DIR=./seeds

examples/libpcap/custom.rule

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
func_include pcap_*
2+
# func_key pcap_compile
3+
# PCAP_DEPRECATED
4+
func_exclude pcap_freealldevs,pcap_geterr
5+
func_exclude pcap_dump_file,pcap_file,pcap_dump
6+
func_exclude pcap_open_live,pcap_activate
7+
8+
# type pcap_pkthdr = $opaque
9+
# func pcap_open[$0] = $read_file
10+
# func pcap_dump_open_append[$1] = $write_file

examples/libpcap/hopper.config

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Configurations for hopper fuzzer
2+
3+
# Full path for header file
4+
TEST_HEADER=/data/workspace/fuzzing_bench/libpcap/src/pcap/pcap.h
5+
6+
# Full path to shared library
7+
TEST_LIBRARY=/data/workspace/fuzzing_bench/libpcap/build/hopper_build/libpcap.so.1.10.1
8+
9+
# Output directory
10+
OUT_DIR=output
11+
12+
# Custom rule for invoking API functions
13+
CUSTOM_RULES=custom.rule
14+
15+
# Set map size
16+
HOPPER_MAP_SIZE_POW2=18
17+
18+
# Do not use API-senitive
19+
#HOPPER_API_INSENSITIVE_COV=1
20+
21+
# Set seeds
22+
HOPPER_SEED_DIR=./seeds
23+
24+
# Set the header include path
25+
HOPPER_INCLUDE_SEARCH_PATH=/data/workspace/fuzzing_bench/libpcap/src
26+

examples/libpcap/seeds/1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
host 192.168.1.1

examples/libpcap/seeds/2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
port 80

examples/libpcap/seeds/3.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tcp[tcpflags]&tcp-syn != 0 or tcp[tcpflags]&tcp-fin != 0 or tcp[tcpflags]&tcp-rst != 0

examples/libpcap/seeds/4.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ether[12:2] = 0x800 or ether[12:2] = 0x8100 or ether[0] & 0x80 != 0 or ether[12:2] = 0x9100

examples/libpcap/seeds/5.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vlan 186 and ip

examples/libpcap/seeds/6.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ip and ((icmp and dst host 1.1.1.1 and not host 2.2.2.2) or (host 1.1.1.1 and src host 3.3.3.3))

examples/libpcap/seeds/7.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
not vlan and tcp port 80
114 Bytes
Binary file not shown.

examples/libpng/hopper.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ CUSTOM_RULES=custom.rule
1818
HOPPER_MAP_SIZE_POW2=18
1919

2020
# set seeds for hopper
21-
# HOPPER_SEED_DIR=seeds
21+
# HOPPER_SEED_DIR=seeds

examples/libvpx/custom.rule

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func_include vpx_*
2+
// func_include vpx_codec_dec_init_ver,vpx_codec_vp9_dx,vpx_codec_decode
3+
// func_key vpx_codec_decode,vpx_codec_get_frame
4+
func_exclude vpx_img_free,vpx_codec_control_

examples/libvpx/hopper.config

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Configurations for hopper fuzzer
2+
3+
# Full path for header file
4+
TEST_HEADER=vpx_all.h
5+
6+
# Full path to shared library
7+
TEST_LIBRARY=/data/workspace/fuzzing_bench/libvpx/build/hopper_build/libvpx.so.7.0.0
8+
9+
# Output directory
10+
OUT_DIR=output
11+
12+
# Set map size for branch counting
13+
HOPPER_MAP_SIZE_POW2=18
14+
15+
# Set dictionary for bytes
16+
HOPPER_DICT=./vpx.dict
17+
18+
# Set the header include path
19+
HOPPER_INCLUDE_SEARCH_PATH=/data/workspace/fuzzing_bench/libvpx/build/hopper_build

examples/libvpx/vpx.dict

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# IVF Signature + version (bytes 0-5)
2+
kw1="DKIF\x00\x00"
3+
4+
# VP9 codec fourCC (bytes 8-11)
5+
kw2="VP90"
6+
7+
# VP8 codec fourCC (bytes 8-11)
8+
kw3="VP80"

examples/re2/custom.rule

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
func_include cre2_*
2+
func_exclude cre2_delete,cre2_set_delete,cre2_named_groups_iter_delete
3+
4+
type cre2_string_t[length] = $len(data)

examples/re2/hopper.config

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Configurations for hopper fuzzer
2+
3+
# Full path for header file
4+
TEST_HEADER=/data/workspace/fuzzing_bench/re2/cre2.h
5+
6+
# Full path to shared library
7+
TEST_LIB_DIR=/data/workspace/fuzzing_bench/re2/build/hopper_build/
8+
TEST_LIBRARY=${TEST_LIB_DIR}/cre2/lib/libcre2.so ${TEST_LIB_DIR}/lib/libre2.so.10.0.0
9+
10+
# Output directory
11+
OUT_DIR=output
12+
13+
# Custom rule for invoking API functions
14+
CUSTOM_RULES=custom.rule
15+
16+
# set map size for branch counting
17+
HOPPER_MAP_SIZE_POW2=20
18+
19+
# set seeds for hopper
20+
# HOPPER_SEED_DIR=seeds
21+
22+
23+
# target library
24+
HOPPER_TEST_LIBRARY=cre2/lib/libre2.so
25+
26+
HOPPER_CUSTOM_RULES=$SRC_DIR/../custom_rule

examples/sqlite3/hopper.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Configurations for hopper fuzzer
22

3-
LIB_DIR=/data/workspace/fuzzing_bench/sqlite3/build/hopper_build
3+
TEST_LIB_DIR=/data/workspace/fuzzing_bench/sqlite3/build/hopper_build
44

55
# Full path for header file
6-
TEST_HEADER=${LIB_DIR}/sqlite3.h
6+
TEST_HEADER=${TEST_LIB_DIR}/sqlite3.h
77

88
# Full path to shared library
9-
TEST_LIBRARY=${LIB_DIR}/.libs/libsqlite3.so
9+
TEST_LIBRARY=${TEST_LIB_DIR}/.libs/libsqlite3.so
1010

1111
# Output directory
1212
OUT_DIR=output
@@ -18,4 +18,4 @@ CUSTOM_RULES=custom.rule
1818
HOPPER_MAP_SIZE_POW2=20
1919

2020
# set seeds for hopper
21-
# HOPPER_SEED_DIR=seeds
21+
# HOPPER_SEED_DIR=seeds

examples/zlib/hopper.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ CUSTOM_RULES=custom.rule
1616
HOPPER_MAP_SIZE_POW2=18
1717

1818
# set seeds for hopper
19-
# HOPPER_SEED_DIR=seeds
19+
# HOPPER_SEED_DIR=seeds

hopper

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if [[ -e "hopper.config" ]]; then
3636
while IFS='=' read -r key value; do
3737
if [[ $key && $value ]]; then
3838
declare -x "$key=$value"
39-
# echo "config file set $key = $value"
39+
echo "config file set: $key = $value"
4040
fi
4141
done < "hopper.config"
4242
fi
@@ -156,7 +156,7 @@ cov)
156156
set -e
157157
done
158158
# find .so file in output directory.
159-
BIN_FILE=$(find $OUTPUT_DIR -maxdepth 1 -type f -name \*.so)
159+
BIN_FILE=$(find $OUTPUT_DIR -maxdepth 1 -type f -name \*_fuzz.so)
160160
BIN_FILE=$(IFS= ; echo "${BIN_FILE[*]}")
161161
info "bin file: $BIN_FILE"
162162
rm -rf $COV_DIR

hopper-compiler/src/patch/patchelf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use std::{
55
env,
6-
path::{PathBuf},
6+
path::PathBuf,
77
process::Command,
88
};
99

hopper-core/src/fuzz/object/buf.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ impl<T: ObjFuzzable + ObjGenerate> BufMutate for Vec<T> {
8686
return Ok(true);
8787
}
8888
let chunk = &seed.buf[r.lower..r.upper];
89-
super::seq::vec_insert_chunk(buf1, state, *split_at, chunk, r.is_insert)?;
89+
super::seq::vec_insert_chunk(
90+
buf1,
91+
state,
92+
*split_at,
93+
chunk,
94+
r.is_insert,
95+
)?;
9096
} else {
9197
if *split_at >= seed.buf.len() {
9298
return Ok(true);
@@ -188,9 +194,7 @@ impl<T: ObjFuzzable + ObjGenerate> BufMutate for Vec<T> {
188194
let ele_type_name = std::any::type_name::<T>();
189195
let ident = state.key.as_str()?;
190196
let key = format!("{ident}_{ele_type_name}");
191-
let buf1 = unsafe {
192-
std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len())
193-
};
197+
let buf1 = unsafe { std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len()) };
194198
// Get current buffer's hash
195199
let hash = crate::utils::hash_buf(buf1);
196200
// Pick a random entry. Don't splice with yourself.
@@ -221,8 +225,8 @@ impl<T: ObjFuzzable + ObjGenerate> BufMutate for Vec<T> {
221225
range: Some(crate::SpliceRange {
222226
lower,
223227
upper,
224-
is_insert
225-
})
228+
is_insert,
229+
}),
226230
});
227231
}
228232

@@ -313,8 +317,6 @@ impl<T: ObjFuzzable + ObjGenerate> BufMutate for Vec<T> {
313317
}
314318
}
315319

316-
317-
318320
/// Find a suitable splicing location, somewhere between the first and
319321
/// the last differing byte.
320322
fn find_splice_pos(buf1: &[u8], buf2: &[u8]) -> Option<usize> {
@@ -454,7 +456,8 @@ pub fn get_buf_dict_tokens(ident: &str) -> Vec<&'static [u8]> {
454456
let default_dict = crate::config::output_file_path("misc/dict");
455457
let path = if let Ok(path) = std::env::var("HOPPER_DICT") {
456458
crate::log!(info, "load dict path: {}", path);
457-
std::fs::copy(&path, default_dict).unwrap();
459+
std::fs::copy(&path, default_dict)
460+
.expect("fail to open dict file! please check the file is exist or not");
458461
PathBuf::from(path)
459462
} else {
460463
default_dict
@@ -608,7 +611,7 @@ fn test_parse_dict() {
608611
let ret = BUF_DICTS.get_or_init(|| parse_dictionary(buf.as_bytes()));
609612
if ret.is_empty() {
610613
return;
611-
}
614+
}
612615
let list = get_buf_dict_tokens("abc");
613616
assert_eq!(list.len(), 2);
614617
let list = get_buf_dict_tokens("test");

hopper-harness/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ fn link_libraries() {
150150
}
151151
println!("cargo:rustc-link-search=native={dir}");
152152
}
153+
#[cfg(target_os = "linux")]
154+
println!("cargo:rustc-link-arg=-Wl,--allow-shlib-undefined");
153155
}
154156

155157
fn main() {

0 commit comments

Comments
 (0)