@@ -170,6 +170,7 @@ def process_afl_test_cases(cargs):
170
170
171
171
cov_paths ['diff' ] = "%s/%s" % \
172
172
(cov_paths ['diff_dir' ], os .path .basename (f ))
173
+ id_range_update (f , cov_paths )
173
174
174
175
### execute the command to generate code coverage stats
175
176
### for the current AFL test case file
@@ -191,6 +192,7 @@ def process_afl_test_cases(cargs):
191
192
do_coverage = True
192
193
193
194
if do_coverage and not cargs .coverage_at_exit :
195
+
194
196
### generate the code coverage stats for this test case
195
197
lcov_gen_coverage (cov_paths , cargs )
196
198
@@ -199,6 +201,10 @@ def process_afl_test_cases(cargs):
199
201
coverage_diff (curr_cycle , fuzz_dir , cov_paths , f ,
200
202
cov , cargs )
201
203
204
+ if cargs .cover_corpus :
205
+ ### reset the range values
206
+ cov_paths ['id_min' ] = cov_paths ['id_max' ] = - 1
207
+
202
208
if cargs .lcov_web_all :
203
209
gen_web_cov_report (fuzz_dir , cov_paths , cargs )
204
210
@@ -265,16 +271,39 @@ def process_afl_test_cases(cargs):
265
271
266
272
return rv
267
273
274
+ def id_range_update (afl_file , cov_paths ):
275
+
276
+ id_val = int (os .path .basename (afl_file ).split (',' )[0 ].split (':' )[1 ])
277
+
278
+ if cov_paths ['id_min' ] == - 1 :
279
+ cov_paths ['id_min' ] = id_val
280
+ elif id_val < cov_paths ['id_min' ]:
281
+ cov_paths ['id_min' ] = id_val
282
+
283
+ if cov_paths ['id_max' ] == - 1 :
284
+ cov_paths ['id_max' ] = id_val
285
+ elif id_val > cov_paths ['id_max' ]:
286
+ cov_paths ['id_max' ] = id_val
287
+
288
+ return
289
+
268
290
def coverage_diff (cycle_num , fuzz_dir , cov_paths , afl_file , cov , cargs ):
269
291
270
292
log_lines = []
271
293
delta_log_lines = []
272
294
print_diff_header = True
273
295
296
+ ### defaults
274
297
a_file = '(init)'
275
298
if cov_paths ['id_file' ]:
276
299
a_file = cov_paths ['id_file' ]
277
- b_file = os .path .basename (afl_file )
300
+ delta_file = b_file = os .path .basename (afl_file )
301
+
302
+ if cargs .cover_corpus or cargs .coverage_at_exit :
303
+ a_file = 'id:%d...' % cov_paths ['id_min' ]
304
+ b_file = 'id:%d...' % cov_paths ['id_max' ]
305
+ delta_file = 'id:[%d-%d]...' % \
306
+ (cov_paths ['id_min' ], cov_paths ['id_max' ])
278
307
279
308
new_cov = extract_coverage (cov_paths ['lcov_info_final' ], cargs )
280
309
@@ -301,10 +330,10 @@ def coverage_diff(cycle_num, fuzz_dir, cov_paths, afl_file, cov, cargs):
301
330
if ctype == 'line' :
302
331
if cargs .coverage_include_lines :
303
332
delta_log_lines .append ("%s, %s, %s, %s, %s\n " \
304
- % (b_file , cycle_num , f , ctype , val ))
333
+ % (delta_file , cycle_num , f , ctype , val ))
305
334
else :
306
335
delta_log_lines .append ("%s, %s, %s, %s, %s\n " \
307
- % (b_file , cycle_num , f , ctype , val ))
336
+ % (delta_file , cycle_num , f , ctype , val ))
308
337
elif f in cov ['zero' ] and f in cov ['pos' ]:
309
338
for ctype in new_cov ['pos' ][f ]:
310
339
for val in sorted (new_cov ['pos' ][f ][ctype ]):
@@ -321,11 +350,11 @@ def coverage_diff(cycle_num, fuzz_dir, cov_paths, afl_file, cov, cargs):
321
350
if ctype == 'line' :
322
351
if cargs .coverage_include_lines :
323
352
delta_log_lines .append ("%s, %s, %s, %s, %s\n " \
324
- % (b_file , cycle_num , f , \
353
+ % (delta_file , cycle_num , f , \
325
354
ctype , val ))
326
355
else :
327
356
delta_log_lines .append ("%s, %s, %s, %s, %s\n " \
328
- % (b_file , cycle_num , f , \
357
+ % (delta_file , cycle_num , f , \
329
358
ctype , val ))
330
359
331
360
### now that new positive coverage has been added, reset zero
@@ -724,8 +753,10 @@ def init_tracking(cov_paths, cargs):
724
753
cov_paths ['id_delta_cov' ] = "%s/id-delta-cov" % cov_paths ['top_dir' ]
725
754
cov_paths ['zero_cov' ] = "%s/zero-cov" % cov_paths ['top_dir' ]
726
755
cov_paths ['pos_cov' ] = "%s/pos-cov" % cov_paths ['top_dir' ]
727
- cov_paths ['id_file' ] = ''
728
756
cov_paths ['diff' ] = ''
757
+ cov_paths ['id_file' ] = ''
758
+ cov_paths ['id_min' ] = - 1 ### used in --cover-corpus mode
759
+ cov_paths ['id_max' ] = - 1 ### used in --cover-corpus mode
729
760
730
761
### raw lcov files
731
762
cov_paths ['lcov_base' ] = "%s/trace.lcov_base" % cov_paths ['lcov_dir' ]
@@ -949,7 +980,10 @@ def mkdirs(cov_paths, cargs):
949
980
950
981
### write coverage results in the following format
951
982
cfile = open (cov_paths ['id_delta_cov' ], 'w' )
952
- cfile .write ("# id:NNNNNN*_file, cycle, src_file, coverage_type, fcn/line\n " )
983
+ if cargs .cover_corpus or cargs .coverage_at_exit :
984
+ cfile .write ("# id:[range]..., cycle, src_file, coverage_type, fcn/line\n " )
985
+ else :
986
+ cfile .write ("# id:NNNNNN*_file, cycle, src_file, coverage_type, fcn/line\n " )
953
987
cfile .close ()
954
988
955
989
return
0 commit comments