Skip to content

Commit fbd781f

Browse files
committed
Merge branch 'dev' of github.com:aflplusplus/aflplusplus into dev
2 parents 62306f5 + 1d15048 commit fbd781f

File tree

9 files changed

+152
-21
lines changed

9 files changed

+152
-21
lines changed

examples/aflpp_driver/aflpp_driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,18 @@ int main(int argc, char **argv) {
252252
else if(argc == 2 && (N = atoi(argv[1])) > 0)
253253
Printf("WARNING: using the deprecated call style `%s %d`\n", argv[0], N);
254254
else if (argc > 1) {
255-
if (!getenv("AFL_DRIVER_DONT_DEFER")) {
255+
// if (!getenv("AFL_DRIVER_DONT_DEFER")) {
256256
__afl_sharedmem_fuzzing = 0;
257257
__afl_manual_init();
258-
}
258+
// }
259259
return ExecuteFilesOnyByOne(argc, argv);
260260
exit(0);
261261
}
262262

263263
assert(N > 0);
264264

265-
if (!getenv("AFL_DRIVER_DONT_DEFER"))
266-
__afl_manual_init();
265+
// if (!getenv("AFL_DRIVER_DONT_DEFER"))
266+
__afl_manual_init();
267267

268268
// Call LLVMFuzzerTestOneInput here so that coverage caused by initialization
269269
// on the first execution of LLVMFuzzerTestOneInput is ignored.
@@ -272,7 +272,7 @@ int main(int argc, char **argv) {
272272

273273
int num_runs = 0;
274274
while (__afl_persistent_loop(N)) {
275-
if (__afl_fuzz_len > 0) {
275+
if (__afl_fuzz_len) {
276276
num_runs++;
277277
LLVMFuzzerTestOneInput(__afl_fuzz_ptr, __afl_fuzz_len);
278278
}

examples/persistent_demo/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
all:
22
afl-clang-fast -o persistent_demo persistent_demo.c
33
afl-clang-fast -o persistent_demo_new persistent_demo_new.c
4+
AFL_DONT_OPTIMIZE=1 afl-clang-fast -o test-instr test-instr.c
5+
6+
document:
7+
AFL_DONT_OPTIMIZE=1 afl-clang-fast -D_AFL_DOCUMENT_MUTATIONS -o test-instr test-instr.c
48

59
clean:
6-
rm -f persistent_demo persistent_demo_new
10+
rm -f persistent_demo persistent_demo_new test-instr

examples/persistent_demo/persistent_demo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int main(int argc, char **argv) {
4141
terminate normally. This limits the impact of accidental memory leaks
4242
and similar hiccups. */
4343

44+
__AFL_INIT();
4445
while (__AFL_LOOP(1000)) {
4546

4647
/*** PLACEHOLDER CODE ***/

examples/persistent_demo/persistent_demo_new.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int main(int argc, char **argv) {
4242
terminate normally. This limits the impact of accidental memory leaks
4343
and similar hiccups. */
4444

45+
__AFL_INIT();
4546
buf = __AFL_FUZZ_TESTCASE_BUF;
4647

4748
while (__AFL_LOOP(1000)) {

examples/persistent_demo/test-instr.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
american fuzzy lop++ - a trivial program to test the build
3+
--------------------------------------------------------
4+
Originally written by Michal Zalewski
5+
Copyright 2014 Google Inc. All rights reserved.
6+
Copyright 2019-2020 AFLplusplus Project. All rights reserved.
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at:
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
*/
12+
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
#include <unistd.h>
16+
#include <string.h>
17+
#include <sys/types.h>
18+
#include <sys/stat.h>
19+
#include <fcntl.h>
20+
21+
__AFL_FUZZ_INIT();
22+
23+
int main(int argc, char **argv) {
24+
25+
__AFL_INIT();
26+
unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF;
27+
28+
while (__AFL_LOOP(2147483647)) {
29+
30+
unsigned int len = __AFL_FUZZ_TESTCASE_LEN;
31+
32+
#ifdef _AFL_DOCUMENT_MUTATIONS
33+
static unsigned int counter = 0;
34+
char fn[32];
35+
sprintf(fn, "%09u:test-instr", counter);
36+
int fd_doc = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600);
37+
if (fd_doc >= 0) {
38+
39+
if (write(fd_doc, buf, len) != __afl_fuzz_len) {
40+
41+
fprintf(stderr, "write of mutation file failed: %s\n", fn);
42+
unlink(fn);
43+
44+
}
45+
46+
close(fd_doc);
47+
48+
}
49+
50+
counter++;
51+
#endif
52+
53+
if (!len) continue;
54+
55+
if (buf[0] == '0')
56+
printf("Looks like a zero to me!\n");
57+
else if (buf[0] == '1')
58+
printf("Pretty sure that is a one!\n");
59+
else
60+
printf("Neither one or zero? How quaint!\n");
61+
62+
}
63+
64+
return 0;
65+
66+
}
67+

llvm_mode/GNUmakefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,21 @@ endif
354354
../cmplog-instructions-pass.so: cmplog-instructions-pass.cc afl-llvm-common.o | test_deps
355355
$(CXX) $(CLANG_CFL) -shared $< -o $@ $(CLANG_LFL) afl-llvm-common.o
356356

357+
document:
358+
$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS) -Wno-unused-result -fPIC -c afl-llvm-rt.o.c -o ../afl-llvm-rt.o
359+
@$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS) -Wno-unused-result -m32 -fPIC -c afl-llvm-rt.o.c -o ../afl-llvm-rt-32.o 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
360+
@$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS) -Wno-unused-result -m64 -fPIC -c afl-llvm-rt.o.c -o ../afl-llvm-rt-64.o 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
361+
357362
../afl-llvm-rt.o: afl-llvm-rt.o.c | test_deps
358363
$(CLANG_BIN) $(CFLAGS) -Wno-unused-result -fPIC -c $< -o $@
359364

360365
../afl-llvm-rt-32.o: afl-llvm-rt.o.c | test_deps
361366
@printf "[*] Building 32-bit variant of the runtime (-m32)... "
362-
@$(CC_SAVE) $(CFLAGS) -Wno-unused-result -m32 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
367+
@$(CLANG_BIN) $(CFLAGS) -Wno-unused-result -m32 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
363368

364369
../afl-llvm-rt-64.o: afl-llvm-rt.o.c | test_deps
365370
@printf "[*] Building 64-bit variant of the runtime (-m64)... "
366-
@$(CC_SAVE) $(CFLAGS) -Wno-unused-result -m64 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
371+
@$(CLANG_BIN) $(CFLAGS) -Wno-unused-result -m64 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
367372

368373
test_build: $(PROGS)
369374
@echo "[*] Testing the CC wrapper and instrumentation output..."

llvm_mode/afl-llvm-rt.o.c

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ u8 __afl_area_initial[MAP_INITIAL_SIZE];
7474
#else
7575
u8 __afl_area_initial[MAP_SIZE];
7676
#endif
77-
u8 *__afl_area_ptr = __afl_area_initial;
78-
u8 *__afl_dictionary;
79-
u8 *__afl_fuzz_ptr;
80-
u32 __afl_fuzz_len;
77+
u8 * __afl_area_ptr = __afl_area_initial;
78+
u8 * __afl_dictionary;
79+
u8 * __afl_fuzz_ptr;
80+
u32 __afl_fuzz_len;
81+
u32 __afl_fuzz_len_dummy;
82+
u32 *__afl_fuzz_len_shmem = &__afl_fuzz_len_dummy;
8183

8284
u32 __afl_final_loc;
8385
u32 __afl_map_size = MAP_SIZE;
@@ -164,6 +166,9 @@ static void __afl_map_shm_fuzz() {
164166

165167
}
166168

169+
__afl_fuzz_len_shmem = (u32 *)mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE,
170+
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
171+
167172
}
168173

169174
/* SHM setup. */
@@ -443,9 +448,35 @@ static void __afl_start_snapshots(void) {
443448

444449
}
445450

446-
__afl_fuzz_len = (was_killed >> 8);
451+
*__afl_fuzz_len_shmem = __afl_fuzz_len = (was_killed >> 8);
447452
was_killed = (was_killed & 0xff);
448453

454+
#ifdef _AFL_DOCUMENT_MUTATIONS
455+
if (__afl_fuzz_ptr) {
456+
457+
static uint32_t counter = 0;
458+
char fn[32];
459+
sprintf(fn, "%09u:forkserver", counter);
460+
s32 fd_doc = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600);
461+
if (fd_doc >= 0) {
462+
463+
if (write(fd_doc, __afl_fuzz_ptr, __afl_fuzz_len) != __afl_fuzz_len) {
464+
465+
fprintf(stderr, "write of mutation file failed: %s\n", fn);
466+
unlink(fn);
467+
468+
}
469+
470+
close(fd_doc);
471+
472+
}
473+
474+
counter++;
475+
476+
}
477+
478+
#endif
479+
449480
/* If we stopped the child in persistent mode, but there was a race
450481
condition and afl-fuzz already issued SIGKILL, write off the old
451482
process. */
@@ -620,9 +651,35 @@ static void __afl_start_forkserver(void) {
620651

621652
}
622653

623-
__afl_fuzz_len = (was_killed >> 8);
654+
*__afl_fuzz_len_shmem = __afl_fuzz_len = (was_killed >> 8);
624655
was_killed = (was_killed & 0xff);
625656

657+
#ifdef _AFL_DOCUMENT_MUTATIONS
658+
if (__afl_fuzz_ptr) {
659+
660+
static uint32_t counter = 0;
661+
char fn[32];
662+
sprintf(fn, "%09u:forkserver", counter);
663+
s32 fd_doc = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600);
664+
if (fd_doc >= 0) {
665+
666+
if (write(fd_doc, __afl_fuzz_ptr, __afl_fuzz_len) != __afl_fuzz_len) {
667+
668+
fprintf(stderr, "write of mutation file failed: %s\n", fn);
669+
unlink(fn);
670+
671+
}
672+
673+
close(fd_doc);
674+
675+
}
676+
677+
counter++;
678+
679+
}
680+
681+
#endif
682+
626683
/* If we stopped the child in persistent mode, but there was a race
627684
condition and afl-fuzz already issued SIGKILL, write off the old
628685
process. */
@@ -719,6 +776,8 @@ int __afl_persistent_loop(unsigned int max_cnt) {
719776

720777
raise(SIGSTOP);
721778

779+
__afl_fuzz_len = *__afl_fuzz_len_shmem;
780+
722781
__afl_area_ptr[0] = 1;
723782
memset(__afl_prev_loc, 0, NGRAM_SIZE_MAX * sizeof(PREV_LOC_T));
724783

src/afl-fuzz-init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,6 @@ static void handle_skipreq(int sig) {
19491949

19501950
}
19511951

1952-
19531952
/* Setup shared map for fuzzing with input via sharedmem */
19541953

19551954
void setup_testcase_shmem(afl_state_t *afl) {
@@ -1978,7 +1977,6 @@ void setup_testcase_shmem(afl_state_t *afl) {
19781977

19791978
}
19801979

1981-
19821980
/* Do a PATH search and find target binary to see that it exists and
19831981
isn't a shell script - a common and painful mistake. We also check for
19841982
a valid ELF header and for evidence of AFL instrumentation. */

src/afl-fuzz.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,11 +1179,7 @@ int main(int argc, char **argv_orig, char **envp) {
11791179

11801180
check_binary(afl, argv[optind]);
11811181

1182-
if (afl->shmem_testcase_mode) {
1183-
1184-
setup_testcase_shmem(afl);
1185-
1186-
}
1182+
if (afl->shmem_testcase_mode) { setup_testcase_shmem(afl); }
11871183

11881184
afl->start_time = get_cur_time();
11891185

0 commit comments

Comments
 (0)