Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Include all loader errors when failing #3509

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/agent/dynamic-library/src/bin/dynamic-library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,35 @@ fn main() -> Result<()> {
cmd.env("LD_LIBRARY_PATH", path);
}

let missing = find_missing(cmd)?;
let (missing, errors) = find_missing(cmd)?;

if missing.is_empty() {
println!("no missing libraries");
} else {
for lib in missing {
println!("missing library: {lib:x?}");
}

if !errors.is_empty() {
println!();

for err in errors {
println!("error: {err}");
}
}
}

Ok(())
}

#[cfg(target_os = "linux")]
fn find_missing(cmd: Command) -> Result<Vec<String>> {
Ok(dynamic_library::linux::find_missing(cmd)?
.drain()
.map(|m| m.name)
.collect())
fn find_missing(cmd: Command) -> Result<(Vec<String>, Vec<String>)> {
let (missing, errors) = dynamic_library::linux::find_missing(cmd)?;
Ok((missing.into_iter().map(|m| m.name).collect(), errors))
}

#[cfg(target_os = "windows")]
fn find_missing(cmd: Command) -> Result<Vec<String>> {
Ok(dynamic_library::windows::find_missing(cmd)?
.into_iter()
.map(|m| m.name)
.collect())
fn find_missing(cmd: Command) -> Result<(Vec<String>, Vec<String>)> {
let (missing, errors) = dynamic_library::windows::find_missing(cmd)?;
Ok((missing.into_iter().map(|m| m.name).collect(), errors))
}
8 changes: 5 additions & 3 deletions src/agent/dynamic-library/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use regex::Regex;

const LD_LIBRARY_PATH: &str = "LD_LIBRARY_PATH";

pub fn find_missing(mut cmd: Command) -> Result<HashSet<MissingDynamicLibrary>, io::Error> {
pub fn find_missing(
mut cmd: Command,
) -> Result<(HashSet<MissingDynamicLibrary>, Vec<String>), io::Error> {
// Check for missing _linked_ dynamic libraries.
//
// We must do this first to avoid false positives or negatives when parsing `LD_DEBUG`
Expand All @@ -24,7 +26,7 @@ pub fn find_missing(mut cmd: Command) -> Result<HashSet<MissingDynamicLibrary>,
let missing_linked = linked.not_found();

if !missing_linked.is_empty() {
return Ok(missing_linked);
return Ok((missing_linked, Vec::new()));
}

// Check for missing _loaded_ dynamic libraries.
Expand All @@ -34,7 +36,7 @@ pub fn find_missing(mut cmd: Command) -> Result<HashSet<MissingDynamicLibrary>,
let output = cmd.output()?;
let logs = LdDebugLogs::parse(&*output.stderr);

Ok(logs.missing())
Ok((logs.missing(), Vec::new()))
}

pub fn get_linked_library_logs(cmd: &Command) -> Result<std::process::Output, io::Error> {
Expand Down
12 changes: 10 additions & 2 deletions src/agent/dynamic-library/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ pub enum CheckDynamicLibrariesError {

pub fn find_missing(
cmd: Command,
) -> Result<Vec<MissingDynamicLibrary>, CheckDynamicLibrariesError> {
) -> Result<(Vec<MissingDynamicLibrary>, Vec<String>), CheckDynamicLibrariesError> {
let mut handler = LoaderSnapsHandler::default();
setup_debugger(cmd, &mut handler)?;
Ok(handler.missing_libraries())
Ok((handler.missing_libraries(), handler.errors()))
}

pub fn get_logs(cmd: Command) -> Result<Vec<String>, CheckDynamicLibrariesError> {
Expand Down Expand Up @@ -273,6 +273,14 @@ impl LoaderSnapsHandler {

missing
}

pub fn errors(&self) -> Vec<String> {
self.debug_strings
.iter()
.filter(|text| text.contains("ERROR:"))
.map(|text| text.to_owned())
.collect()
}
}

impl DebugEventHandler for LoaderSnapsHandler {
Expand Down
16 changes: 9 additions & 7 deletions src/agent/onefuzz/src/libfuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,26 @@ impl LibFuzzer {
if !result.status.success() {
// To provide user-actionable errors, try to identify any missing shared libraries.
match self.find_missing_libraries().await {
Ok(missing) => {
Ok((missing, errors)) => {
if missing.is_empty() {
bail!("fuzzer does not respond to '-help=1'. no missing shared libraries detected. output: {:?}", result);
bail!("fuzzer does not respond to '-help=1'. no missing shared libraries detected. output: {result:?}");
} else {
let missing = missing.join(", ");
let all_errors = errors.join("\n");
Porges marked this conversation as resolved.
Show resolved Hide resolved

bail!("fuzzer does not respond to '-help=1'. missing shared libraries: {}. output: {:?}", missing, result);
bail!("fuzzer does not respond to '-help=1'. missing shared libraries: {missing}. output: {result:?}. all errors: {all_errors}");
}
}
Err(err) => {
bail!("fuzzer does not respond to '-help=1'. additional error while checking for missing shared libraries: {}. output: {:?}", err, result);
bail!("fuzzer does not respond to '-help=1'. additional error while checking for missing shared libraries: {err}. output: {result:?}");
}
}
}

Ok(())
}

async fn find_missing_libraries(&self) -> Result<Vec<String>> {
async fn find_missing_libraries(&self) -> Result<(Vec<String>, Vec<String>)> {
let cmd = self.build_std_command(None, None, None, None, None)?;

#[cfg(target_os = "linux")]
Expand All @@ -333,10 +334,11 @@ impl LibFuzzer {
#[cfg(target_os = "windows")]
let blocking = move || dynamic_library::windows::find_missing(cmd);

let missing = tokio::task::spawn_blocking(blocking).await??;
let (missing, errors) = tokio::task::spawn_blocking(blocking).await??;

let missing = missing.into_iter().map(|m| m.name).collect();

Ok(missing)
Ok((missing, errors))
}

pub fn fuzz(
Expand Down
4 changes: 2 additions & 2 deletions src/proxy-manager/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading