libafl_cc: fix configuration support (#1595)

* libafl_cc: fix configuration support

* fmt

* clippy
This commit is contained in:
s1341 2023-10-02 17:48:33 +03:00 committed by GitHub
parent f35c59131d
commit a27553daec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 32 deletions

View File

@ -194,7 +194,7 @@ impl ToolWrapper for ClangWrapper {
continue;
}
}
"--libafl-ignore-configurations" => {
"--libafl-ignore-configurations" | "-print-prog-name=ld" => {
self.ignoring_configurations = true;
i += 1;
continue;
@ -346,42 +346,51 @@ impl ToolWrapper for ClangWrapper {
})
.collect::<Vec<_>>();
if let crate::Configuration::Default = configuration {
if let Some(output) = self.output.clone() {
let output = configuration.replace_extension(&output);
let new_filename = output.into_os_string().into_string().unwrap();
args.push("-o".to_string());
args.push(new_filename);
args.extend_from_slice(base_args.as_slice());
} else {
// No output specified, we need to rewrite the single .c file's name.
args.extend(
base_args
.iter()
.map(|r| {
let arg_as_path = std::path::PathBuf::from(r);
if r.ends_with('.') {
r.to_string()
}
} else if let Some(output) = self.output.clone() {
let output = configuration.replace_extension(&output);
let new_filename = output.into_os_string().into_string().unwrap();
args.push("-o".to_string());
args.push(new_filename);
} else {
// No output specified, we need to rewrite the single .c file's name into a -o
// argument.
for arg in &base_args {
let arg_as_path = std::path::PathBuf::from(arg);
if !arg.ends_with('.') && !arg.starts_with('-') {
if let Some(extension) = arg_as_path.extension() {
let extension = extension.to_str().unwrap();
let extension_lowercase = extension.to_lowercase();
match &extension_lowercase[..] {
"c" | "cc" | "cxx" | "cpp" => {
configuration.replace_extension(&arg_as_path)
}
_ => arg_as_path,
}
} else {
arg_as_path
}
args.push("-o".to_string());
args.push(if self.linking {
configuration
.replace_extension(&std::path::PathBuf::from("a.out"))
.into_os_string()
.into_string()
.unwrap()
} else {
let mut result = configuration.replace_extension(&arg_as_path);
result.set_extension("o");
result.into_os_string().into_string().unwrap()
});
break;
}
})
.collect::<Vec<_>>(),
);
_ => {}
}
}
}
}
}
args.extend_from_slice(base_args.as_slice());
args.extend_from_slice(&configuration.to_flags()?);

View File

@ -178,9 +178,7 @@ impl ToolWrapper for LibtoolWrapper {
let extension = extension.to_str().unwrap();
let extension_lowercase = extension.to_lowercase();
match &extension_lowercase[..] {
"o" | "lo" | "a" | "la" | "so" => {
configuration.replace_extension(&arg_as_path)
}
"lo" | "la" | "so" => configuration.replace_extension(&arg_as_path),
_ => arg_as_path,
}
} else {