@@ -19,33 +19,21 @@ def fuzz_function_exists?(file_path)
1919 reader . getc == '1'
2020end
2121
22- if ARGV . length != 1
23- puts 'USAGE: fuzz.rb <FILE TO FUZZ>'
24- exit ( 1 )
25- end
26- file_path = ARGV [ 0 ] . freeze
27-
28- # TODO: ensure we don't load this file
29- if !fuzz_function_exists? ( file_path )
30- puts "ERROR: `fuzz` function doesn’t exist in #{ file_path } "
31- exit ( 1 )
32- end
33-
34- reader , writer = IO . pipe
35-
36- fork do
37- seen = { }
38- loop do
39- encoded_bytes , cov_hash = reader . gets . strip . split ( '_' )
22+ def start_reporting_process ( reader )
23+ fork do
24+ seen = { }
25+ loop do
26+ encoded_bytes , cov_hash = reader . gets . strip . split ( '_' )
4027
41- if !seen . include? ( cov_hash )
42- seen [ cov_hash ] = Base64 . strict_decode64 ( encoded_bytes )
43- puts ( seen )
28+ if !seen . include? ( cov_hash )
29+ seen [ cov_hash ] = Base64 . strict_decode64 ( encoded_bytes )
30+ puts ( seen )
31+ end
4432 end
4533 end
4634end
4735
48- loop do
36+ def start_fuzzing_process ( writer )
4937 fork do
5038 STDOUT . reopen ( '/dev/null' )
5139 STDIN . reopen ( '/dev/null' )
@@ -64,5 +52,29 @@ def fuzz_function_exists?(file_path)
6452
6553 writer . puts ( Base64 . strict_encode64 ( bytes ) + '_' + Coverage . result . hash . to_s )
6654 end
67- Process . wait
6855end
56+
57+ def run
58+ if ARGV . length != 1
59+ puts 'USAGE: fuzz.rb <FILE TO FUZZ>'
60+ exit ( 1 )
61+ end
62+ file_path = ARGV [ 0 ] . freeze
63+
64+ # TODO: ensure we don't load this file
65+ if !fuzz_function_exists? ( file_path )
66+ puts "ERROR: `fuzz` function doesn’t exist in #{ file_path } "
67+ exit ( 1 )
68+ end
69+
70+ reader , writer = IO . pipe
71+
72+ start_reporting_process ( reader )
73+
74+ loop do
75+ start_fuzzing_process
76+ Process . wait
77+ end
78+ end
79+
80+ run
0 commit comments