The function (except main and LLVMFuzzerTestOneInput*) and global variables declared in driver might cause redefinition if it is also declared in other drivers. To avoid that case, we should rename those functions as unique names in all drivers.
(program: &Path)
| 428 | /// if it is also declared in other drivers. |
| 429 | /// To avoid that case, we should rename those functions as unique names in all drivers. |
| 430 | pub fn fix_driver_naming_conflict(program: &Path) -> Result<()> { |
| 431 | let ast = Executor::extract_program_ast(program)?; |
| 432 | let file_base = program |
| 433 | .file_name() |
| 434 | .unwrap() |
| 435 | .to_string_lossy() |
| 436 | .to_string() |
| 437 | .strip_suffix(".cc") |
| 438 | .unwrap() |
| 439 | .to_string(); |
| 440 | |
| 441 | let mut decls = vec![]; |
| 442 | for child in &ast.inner { |
| 443 | if let Clang::FunctionDecl(fd) = &child.kind { |
| 444 | if is_valid_range(&fd.range) { |
| 445 | decls.push(fd.get_name().trim().to_string()); |
| 446 | } |
| 447 | } |
| 448 | if let Clang::VarDecl(vd) = &child.kind { |
| 449 | if is_valid_range(&vd.range) { |
| 450 | let name = vd.get_name_as_string().trim().to_string(); |
| 451 | decls.push(name); |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | let mut content = std::fs::read_to_string(program)?; |
| 456 | for decl in decls { |
| 457 | if decl.starts_with("LLVM") || decl.starts_with("main") { |
| 458 | continue; |
| 459 | } |
| 460 | if get_func_gadget(&decl).is_some() { |
| 461 | continue; |
| 462 | } |
| 463 | log::debug!("fix definition conflict: {decl} in {program:?}"); |
| 464 | let match_str = format!(r"\b{decl}\b"); |
| 465 | let re = regex::Regex::new(&match_str)?; |
| 466 | let new_func = format!(" {file_base}_{decl}"); |
| 467 | content = re.replace_all(&content, &new_func).to_string(); |
| 468 | } |
| 469 | std::fs::write(program, content)?; |
| 470 | Ok(()) |
| 471 | } |
| 472 | |
| 473 | fn parse_artifact_from_log(fuzz_log: &Path) -> Result<Vec<u8>> { |
| 474 | let fuzzer_dir = get_file_dirname(fuzz_log); |
no test coverage detected