Skip to content

Commit e4f3a97

Browse files
committed
timeout option, auto use default/ if necessary
1 parent ce1e72d commit e4f3a97

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ Version: 0.6.6
1818
This is a modified afl-cov fork because the original author's account is
1919
inactive :-(
2020

21-
It has four changes:
21+
It has several improvements:
2222
* afl-cov now accepts "@@" like AFL++ in the target command parameters
2323
* afl-cov now can send to targets that read on stdin (just omit @@)
24+
* afl-cov has a timeout -T option to hangs are not an issue, default 5s
2425
* afl-cov.sh makes using afl-cov easier (just needs two parameters)
25-
* afl-cov-build.sh makes builing a target for coverage easier
26+
* afl-cov-build.sh makes builing a target for coverage easier, just type
27+
`afl-cov-build.sh make`
2628
* afl-cov/afl-cov.sh/afl-cov-build.sh now support clang coverage, just add
27-
-c to afl-cov.sh/afl-cov-build.sh (and --clang to afl-cov)
29+
-c to afl-cov.sh/afl-cov-build.sh (--clang for afl-cov)
2830
* afl-stat.sh shows the statistics of a run (in progress or completed)
2931

3032
Enjoy!

afl-cov

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ def process_afl_test_cases(cargs):
186186
### for the current AFL test case file
187187
if run_once:
188188
run_cmd(cargs.coverage_cmd.replace('AFL_FILE', f),
189-
cov_paths['log_file'], cargs, NO_OUTPUT, True, f)
189+
cov_paths['log_file'], cargs, NO_OUTPUT, True, f, cargs.timeout)
190190
else:
191191
out_lines = run_cmd(cargs.coverage_cmd.replace('AFL_FILE', f),
192-
cov_paths['log_file'], cargs, WANT_OUTPUT, True, f)[1]
192+
cov_paths['log_file'], cargs, WANT_OUTPUT, True, f, cargs.timeout)[1]
193193
run_once = True
194194

195195
if cargs.afl_queue_id_limit \
@@ -694,7 +694,7 @@ def get_running_pid(stats_file, pid_re):
694694
break
695695
return pid
696696

697-
def run_cmd(cmd, log_file, cargs, collect, aflrun, fn):
697+
def run_cmd(cmd, log_file, cargs, collect, aflrun, fn, timeout=None):
698698

699699
out = []
700700

@@ -714,6 +714,9 @@ def run_cmd(cmd, log_file, cargs, collect, aflrun, fn):
714714
else:
715715
print(" CMD: %s" % cmd)
716716

717+
if timeout:
718+
cmd = 'timeout -s KILL %s %s' % (timeout, cmd)
719+
717720
es = subprocess.call(cmd, stdin=None,
718721
stdout=fh, stderr=subprocess.STDOUT, shell=True)
719722

@@ -1215,6 +1218,8 @@ def parse_cmdline():
12151218
help="Print version and exit", default=False)
12161219
p.add_argument("-q", "--quiet", action='store_true',
12171220
help="Quiet mode", default=False)
1221+
p.add_argument("-T", "--timeout", type=str,
1222+
help="timeout (default 5 seconds)", default='5')
12181223

12191224
return p.parse_args()
12201225

afl-cov.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ test "$1" = "-c" && { OPT2="--clang" ; shift ; }
1919
test "$1" = "-v" && { OPT1="-v" ; shift ; }
2020

2121
test -d "$1" || { echo Error: not a directory: $1 ; exit 1 ; }
22-
test -e "$1"/queue || { echo Error: not an afl-fuzz -o out directory ; exit 1 ; }
2322

24-
HOMEPATH=`dirname $0`
23+
2524
DST=`realpath "$1"`
25+
test -e "$DST"/queue || {
26+
DST="$DST/default"
27+
test -e "$DST"/queue || {
28+
echo Error: not an afl-fuzz -o out directory
29+
exit 1
30+
}
31+
}
32+
33+
HOMEPATH=`dirname $0`
2634
export PATH=$HOMEPATH:$PATH
2735

2836
afl-cov $OPT1 $OPT2 -d "$DST" --cover-corpus --coverage-cmd "$2" --code-dir . --overwrite

0 commit comments

Comments
 (0)