1
+ use std:: io:: Read ;
1
2
use std:: time:: Duration ;
2
3
use serde_derive:: Serialize ;
3
4
use serde_derive:: Deserialize ;
@@ -140,8 +141,32 @@ pub struct FuzzerConfig {
140
141
pub write_protected_input_buffer : bool ,
141
142
pub cow_primary_size : Option < u64 > ,
142
143
pub ipt_filters : [ IptFilter ; 4 ] ,
144
+ pub target_hash : Option < [ u8 ; 20 ] >
143
145
}
144
146
impl FuzzerConfig {
147
+
148
+ fn load_target_hash ( sharedir : & str ) -> Option < [ u8 ; 20 ] > {
149
+ let mut file = File :: open ( format ! ( "{}/TARGET_HASH" , sharedir) ) . ok ( ) ?;
150
+ let mut content = String :: new ( ) ;
151
+ file. read_to_string ( & mut content) . ok ( ) ?;
152
+
153
+ let content = content. trim ( ) ;
154
+
155
+ if content. len ( ) < 40 {
156
+ return None ;
157
+ }
158
+
159
+ let mut bytes = [ 0u8 ; 20 ] ;
160
+ for i in 0 ..20 {
161
+ match u8:: from_str_radix ( & content[ 2 * i..2 * i + 2 ] , 16 ) {
162
+ Ok ( byte) => bytes[ i] = byte,
163
+ Err ( _) => return None ,
164
+ }
165
+ }
166
+
167
+ Some ( bytes)
168
+ }
169
+
145
170
pub fn new_from_loader ( sharedir : & str , default : FuzzerConfigLoader , config : FuzzerConfigLoader ) -> Self {
146
171
147
172
let seed_path = config. seed_path . or ( default. seed_path ) . unwrap ( ) ;
@@ -152,6 +177,8 @@ impl FuzzerConfig{
152
177
Some ( into_absolute_path ( & sharedir, seed_path) )
153
178
} ;
154
179
180
+ let target_hash = Self :: load_target_hash ( & sharedir) ;
181
+
155
182
Self {
156
183
spec_path : format ! ( "{}/spec.msgp" , sharedir) ,
157
184
workdir_path : config. workdir_path . or ( default. workdir_path ) . expect ( "no workdir_path specified" ) ,
@@ -172,6 +199,7 @@ impl FuzzerConfig{
172
199
config. ip2 ,
173
200
config. ip3 ,
174
201
] ,
202
+ target_hash : target_hash,
175
203
}
176
204
}
177
205
}
0 commit comments