MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / handle_file_constraint

Method handle_file_constraint

src/program/transform.rs:179–193  ·  view source on GitHub ↗

write the raw bytes to the "intput_file";

(&mut self, data: &str, size: &str)

Source from the content-addressed store, hash-verified

177
178 // write the raw bytes to the "intput_file";
179 fn handle_file_constraint(&mut self, data: &str, size: &str) -> Result<()> {
180 let re = Regex::new(r"^input_file(\.\w+)?$")?;
181 let visitor = self.get_new_visitor()?;
182 if let Some(file_name) = visitor.match_string_pattern(re) {
183 let ins_loc =
184 if let Some(loc) = crate::ast::loc::get_fuzzer_shim_after_loc(&self.src_file)? {
185 loc
186 } else {
187 visitor.get_function_body_begin_loc()?
188 };
189 let init_stmt = format!("\n\tFILE *input_file_ptr = fopen(\"{file_name}\", \"wb\");\n\tif (input_file_ptr == NULL) {{return 0;}}\n\tfwrite({data}, sizeof(uint8_t), {size}, input_file_ptr);\n\tfclose(input_file_ptr);\n");
190 self.seek_and_rewrite(ins_loc, 0, &init_stmt)?;
191 }
192 Ok(())
193 }
194
195 /// change the 'main' function to fuzzable and receive fuzzer input
196 fn change_fd_to_fuzzer(

Callers 2

transform_to_fuzzerMethod · 0.80
preprocessMethod · 0.80

Calls 5

get_new_visitorMethod · 0.80
match_string_patternMethod · 0.80
seek_and_rewriteMethod · 0.80

Tested by

no test coverage detected