@@ -46,10 +46,6 @@ except ImportError:
46
46
47
47
__version__ = '0.6.1'
48
48
49
- NO_OUTPUT = 0
50
- WANT_OUTPUT = 1
51
- LOG_ERRORS = 2
52
-
53
49
def main ():
54
50
55
51
exit_success = 0
@@ -182,10 +178,10 @@ def process_afl_test_cases(cargs):
182
178
### for the current AFL test case file
183
179
if run_once :
184
180
run_cmd (cargs .coverage_cmd .replace ('AFL_FILE' , f ),
185
- cov_paths ['log_file' ], cargs , NO_OUTPUT )
181
+ cov_paths ['log_file' ], cargs )
186
182
else :
187
183
out_lines = run_cmd (cargs .coverage_cmd .replace ('AFL_FILE' , f ),
188
- cov_paths ['log_file' ], cargs , WANT_OUTPUT )[1 ]
184
+ cov_paths ['log_file' ], cargs )[1 ]
189
185
run_once = True
190
186
191
187
if cargs .afl_queue_id_limit \
@@ -579,29 +575,29 @@ def lcov_gen_coverage(cov_paths, cargs):
579
575
+ " --no-checksum --capture --directory " \
580
576
+ cargs .code_dir + " --output-file " \
581
577
+ cov_paths ['lcov_info' ], \
582
- cov_paths ['log_file' ], cargs , LOG_ERRORS )
578
+ cov_paths ['log_file' ], cargs )
583
579
584
580
if (cargs .disable_lcov_exclude_pattern ):
585
581
out_lines = run_cmd (cargs .lcov_path \
586
582
+ lcov_opts
587
583
+ " --no-checksum -a " + cov_paths ['lcov_base' ] \
588
584
+ " -a " + cov_paths ['lcov_info' ] \
589
585
+ " --output-file " + cov_paths ['lcov_info_final' ], \
590
- cov_paths ['log_file' ], cargs , WANT_OUTPUT )[1 ]
586
+ cov_paths ['log_file' ], cargs )[1 ]
591
587
else :
592
588
tmp_file = NamedTemporaryFile (delete = False )
593
589
run_cmd (cargs .lcov_path \
594
590
+ lcov_opts
595
591
+ " --no-checksum -a " + cov_paths ['lcov_base' ] \
596
592
+ " -a " + cov_paths ['lcov_info' ] \
597
593
+ " --output-file " + tmp_file .name , \
598
- cov_paths ['log_file' ], cargs , LOG_ERRORS )
594
+ cov_paths ['log_file' ], cargs )
599
595
out_lines = run_cmd (cargs .lcov_path \
600
596
+ lcov_opts
601
597
+ " --no-checksum -r " + tmp_file .name \
602
598
+ " " + cargs .lcov_exclude_pattern + " --output-file " \
603
599
+ cov_paths ['lcov_info_final' ],
604
- cov_paths ['log_file' ], cargs , WANT_OUTPUT )[1 ]
600
+ cov_paths ['log_file' ], cargs )[1 ]
605
601
if os .path .exists (tmp_file .name ):
606
602
os .unlink (tmp_file .name )
607
603
@@ -638,7 +634,7 @@ def gen_web_cov_report(fuzz_dir, cov_paths, cargs):
638
634
+ " --output-directory " \
639
635
+ cov_paths ['web_dir' ] + " " \
640
636
+ cov_paths ['lcov_info_final' ], \
641
- cov_paths ['log_file' ], cargs , LOG_ERRORS )
637
+ cov_paths ['log_file' ], cargs )
642
638
643
639
logr ("[+] Final lcov web report: %s/%s" % \
644
640
(cov_paths ['web_dir' ], 'index.html' ), cov_paths ['log_file' ], cargs )
@@ -686,19 +682,18 @@ def get_running_pid(stats_file, pid_re):
686
682
break
687
683
return pid
688
684
689
- def run_cmd (cmd , log_file , cargs , collect ):
685
+ def run_cmd (cmd , log_file , cargs ):
690
686
691
- out = []
687
+ output = []
688
+
689
+ if log_file :
690
+ logr (" CMD: %s" % cmd , log_file , cargs )
692
691
693
692
if cargs .verbose :
694
- if log_file :
695
- logr (" CMD: %s" % cmd , log_file , cargs )
696
- else :
697
- print " CMD: %s" % cmd
693
+ print " CMD: %s" % cmd
698
694
699
695
fh = None
700
- if cargs .disable_cmd_redirection or collect == WANT_OUTPUT \
701
- or collect == LOG_ERRORS :
696
+ if cargs .disable_cmd_redirection :
702
697
fh = NamedTemporaryFile (delete = False )
703
698
else :
704
699
fh = open (os .devnull , 'w' )
@@ -708,23 +703,24 @@ def run_cmd(cmd, log_file, cargs, collect):
708
703
709
704
fh .close ()
710
705
711
- if cargs .disable_cmd_redirection or collect == WANT_OUTPUT \
712
- or collect == LOG_ERRORS :
706
+ if cargs .disable_cmd_redirection :
713
707
with open (fh .name , 'r' ) as f :
714
708
for line in f :
715
- out .append (line .rstrip ('\n ' ))
709
+ output .append (line .rstrip ('\n ' ))
716
710
os .unlink (fh .name )
717
711
718
- if (es != 0 ) and ( collect == LOG_ERRORS or collect == WANT_OUTPUT ) :
712
+ if (es != 0 ):
719
713
if log_file :
720
714
logr (" Non-zero exit status '%d' for CMD: %s" % (es , cmd ),
721
715
log_file , cargs )
722
- for line in out :
716
+ for line in output :
723
717
logr (line , log_file , cargs )
724
718
else :
725
719
print " Non-zero exit status '%d' for CMD: %s" % (es , cmd )
720
+ for line in output :
721
+ print line
726
722
727
- return es , out
723
+ return es , output
728
724
729
725
def import_fuzzing_dirs (cov_paths , cargs ):
730
726
@@ -804,15 +800,15 @@ def init_tracking(cov_paths, cargs):
804
800
run_cmd (cargs .lcov_path \
805
801
+ lcov_opts \
806
802
+ " --no-checksum --zerocounters --directory " \
807
- + cargs .code_dir , cov_paths ['log_file' ], cargs , LOG_ERRORS )
803
+ + cargs .code_dir , cov_paths ['log_file' ], cargs )
808
804
809
805
run_cmd (cargs .lcov_path \
810
806
+ lcov_opts
811
807
+ " --no-checksum --capture --initial" \
812
808
+ " --directory " + cargs .code_dir \
813
809
+ " --output-file " \
814
810
+ cov_paths ['lcov_base' ], \
815
- cov_paths ['log_file' ], cargs , LOG_ERRORS )
811
+ cov_paths ['log_file' ], cargs )
816
812
817
813
return True
818
814
@@ -827,7 +823,7 @@ def is_bin_gcov_enabled(binary, cargs):
827
823
828
824
### run readelf against the binary to see if it contains gcov support
829
825
for line in run_cmd ("%s -a %s" % (cargs .readelf_path , binary ),
830
- False , cargs , WANT_OUTPUT )[1 ]:
826
+ False , cargs )[1 ]:
831
827
if ' __gcov' in line :
832
828
if cargs .validate_args or cargs .gcov_check or cargs .gcov_check_bin :
833
829
print "[+] Binary '%s' is compiled with code coverage support gcc." % binary
0 commit comments