@@ -198,29 +198,47 @@ def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
198
198
{corpus_dir}.
199
199
"""
200
200
logging .info ("Generating corpus to {}" .format (corpus_dir ))
201
+ rpc_target = "rpc"
202
+ has_rpc = rpc_target in targets
203
+ if has_rpc :
204
+ targets .remove (rpc_target )
205
+ targets = [(t , {}) for t in targets ]
206
+ if has_rpc :
207
+ lines = subprocess .run (
208
+ ["git" , "grep" , "--function-context" , "RPC_COMMANDS_SAFE_FOR_FUZZING{" , os .path .join (src_dir , "src" , "test" , "fuzz" , "rpc.cpp" )],
209
+ check = True ,
210
+ stdout = subprocess .PIPE ,
211
+ text = True ,
212
+ ).stdout .splitlines ()
213
+ lines = [l .split ("\" " , 1 )[1 ].split ("\" " )[0 ] for l in lines if l .startswith ("src/test/fuzz/rpc.cpp- \" " )]
214
+ targets += [(rpc_target , {"LIMIT_TO_RPC_COMMAND" : r }) for r in lines ]
201
215
202
- def job (command , t ):
203
- logging .debug ("Running '{}' \n " . format ( " " . join ( command )) )
216
+ def job (command , t , t_env ):
217
+ logging .debug (f "Running '{ command } '" )
204
218
logging .debug ("Command '{}' output:\n '{}'\n " .format (
205
- ' ' . join ( command ) ,
219
+ command ,
206
220
subprocess .run (
207
221
command ,
208
- env = get_fuzz_env (target = t , source_dir = src_dir ),
222
+ env = {
223
+ ** t_env ,
224
+ ** get_fuzz_env (target = t , source_dir = src_dir ),
225
+ },
209
226
check = True ,
210
227
stderr = subprocess .PIPE ,
211
228
text = True ,
212
- ).stderr ))
229
+ ).stderr ,
230
+ ))
213
231
214
232
futures = []
215
- for target in targets :
216
- target_corpus_dir = os . path . join ( corpus_dir , target )
233
+ for target , t_env in targets :
234
+ target_corpus_dir = corpus_dir / target
217
235
os .makedirs (target_corpus_dir , exist_ok = True )
218
236
command = [
219
237
os .path .join (build_dir , 'src' , 'test' , 'fuzz' , 'fuzz' ),
220
238
"-runs=100000" ,
221
239
target_corpus_dir ,
222
240
]
223
- futures .append (fuzz_pool .submit (job , command , target ))
241
+ futures .append (fuzz_pool .submit (job , command , target , t_env ))
224
242
225
243
for future in as_completed (futures ):
226
244
future .result ()
0 commit comments