From 14bc63fa9caecb8f6dff448714bc527134be79ef Mon Sep 17 00:00:00 2001 From: George Pollard Date: Mon, 18 Sep 2023 10:55:25 +1200 Subject: [PATCH 1/4] Include all loader errors when failing --- .../src/bin/dynamic-library.rs | 26 +++++++++++-------- src/agent/dynamic-library/src/linux.rs | 6 +++-- src/agent/dynamic-library/src/windows.rs | 12 +++++++-- src/agent/onefuzz/src/libfuzzer.rs | 16 +++++++----- src/proxy-manager/Cargo.lock | 4 +-- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/agent/dynamic-library/src/bin/dynamic-library.rs b/src/agent/dynamic-library/src/bin/dynamic-library.rs index 97f0b3e7aa..a3c98d6f00 100644 --- a/src/agent/dynamic-library/src/bin/dynamic-library.rs +++ b/src/agent/dynamic-library/src/bin/dynamic-library.rs @@ -38,7 +38,7 @@ 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"); @@ -46,23 +46,27 @@ fn main() -> Result<()> { 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> { - Ok(dynamic_library::linux::find_missing(cmd)? - .drain() - .map(|m| m.name) - .collect()) +fn find_missing(cmd: Command) -> Result { + let (missing, errors) = dynamic_library::linux::find_missing(cmd)?; + Ok((missing.drain().map(|m| m.name).collect(), errors)) } #[cfg(target_os = "windows")] -fn find_missing(cmd: Command) -> Result> { - Ok(dynamic_library::windows::find_missing(cmd)? - .into_iter() - .map(|m| m.name) - .collect()) +fn find_missing(cmd: Command) -> Result<(Vec, Vec)> { + let (missing, errors) = dynamic_library::windows::find_missing(cmd)?; + Ok((missing.into_iter().map(|m| m.name).collect(), errors)) } diff --git a/src/agent/dynamic-library/src/linux.rs b/src/agent/dynamic-library/src/linux.rs index f438e3fa58..4b54edcfbd 100644 --- a/src/agent/dynamic-library/src/linux.rs +++ b/src/agent/dynamic-library/src/linux.rs @@ -13,7 +13,9 @@ use regex::Regex; const LD_LIBRARY_PATH: &str = "LD_LIBRARY_PATH"; -pub fn find_missing(mut cmd: Command) -> Result, io::Error> { +pub fn find_missing( + mut cmd: Command, +) -> Result<(HashSet, Vec), io::Error> { // Check for missing _linked_ dynamic libraries. // // We must do this first to avoid false positives or negatives when parsing `LD_DEBUG` @@ -34,7 +36,7 @@ pub fn find_missing(mut cmd: Command) -> Result, 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 { diff --git a/src/agent/dynamic-library/src/windows.rs b/src/agent/dynamic-library/src/windows.rs index 137d10ea03..be847357b6 100644 --- a/src/agent/dynamic-library/src/windows.rs +++ b/src/agent/dynamic-library/src/windows.rs @@ -26,10 +26,10 @@ pub enum CheckDynamicLibrariesError { pub fn find_missing( cmd: Command, -) -> Result, CheckDynamicLibrariesError> { +) -> Result<(Vec, Vec), 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, CheckDynamicLibrariesError> { @@ -273,6 +273,14 @@ impl LoaderSnapsHandler { missing } + + pub fn errors(&self) -> Vec { + self.debug_strings + .iter() + .filter(|text| text.contains("ERROR:")) + .map(|text| text.to_owned()) + .collect() + } } impl DebugEventHandler for LoaderSnapsHandler { diff --git a/src/agent/onefuzz/src/libfuzzer.rs b/src/agent/onefuzz/src/libfuzzer.rs index 00b24bf4e9..3c173a0fa9 100644 --- a/src/agent/onefuzz/src/libfuzzer.rs +++ b/src/agent/onefuzz/src/libfuzzer.rs @@ -306,17 +306,18 @@ 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"); - 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:?}"); } } } @@ -324,7 +325,7 @@ impl LibFuzzer { Ok(()) } - async fn find_missing_libraries(&self) -> Result> { + async fn find_missing_libraries(&self) -> Result<(Vec, Vec)> { let cmd = self.build_std_command(None, None, None, None, None)?; #[cfg(target_os = "linux")] @@ -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( diff --git a/src/proxy-manager/Cargo.lock b/src/proxy-manager/Cargo.lock index e86da294a7..a9a7b85c6d 100644 --- a/src/proxy-manager/Cargo.lock +++ b/src/proxy-manager/Cargo.lock @@ -199,9 +199,9 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" dependencies = [ "serde", ] From 4ca4a2f452f424b772305ff90a05e9d548499571 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Sun, 17 Sep 2023 23:17:45 +0000 Subject: [PATCH 2/4] Missed one --- src/agent/dynamic-library/src/linux.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/dynamic-library/src/linux.rs b/src/agent/dynamic-library/src/linux.rs index 4b54edcfbd..98742c54a8 100644 --- a/src/agent/dynamic-library/src/linux.rs +++ b/src/agent/dynamic-library/src/linux.rs @@ -26,7 +26,7 @@ pub fn find_missing( 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. From a1010b0c18cb88f60a6519b41c9929fa33412936 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Mon, 18 Sep 2023 20:54:15 +0000 Subject: [PATCH 3/4] Missed another --- src/agent/dynamic-library/src/bin/dynamic-library.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/dynamic-library/src/bin/dynamic-library.rs b/src/agent/dynamic-library/src/bin/dynamic-library.rs index a3c98d6f00..2b89281c40 100644 --- a/src/agent/dynamic-library/src/bin/dynamic-library.rs +++ b/src/agent/dynamic-library/src/bin/dynamic-library.rs @@ -60,7 +60,7 @@ fn main() -> Result<()> { } #[cfg(target_os = "linux")] -fn find_missing(cmd: Command) -> Result { +fn find_missing(cmd: Command) -> Result<(Vec, Vec)> { let (missing, errors) = dynamic_library::linux::find_missing(cmd)?; Ok((missing.drain().map(|m| m.name).collect(), errors)) } From 31f31bd78a8ac1263b861d89b334548bf98c6a10 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 26 Sep 2023 20:39:38 +0000 Subject: [PATCH 4/4] build fix --- src/agent/dynamic-library/src/bin/dynamic-library.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/dynamic-library/src/bin/dynamic-library.rs b/src/agent/dynamic-library/src/bin/dynamic-library.rs index 2b89281c40..83cbb372c1 100644 --- a/src/agent/dynamic-library/src/bin/dynamic-library.rs +++ b/src/agent/dynamic-library/src/bin/dynamic-library.rs @@ -62,7 +62,7 @@ fn main() -> Result<()> { #[cfg(target_os = "linux")] fn find_missing(cmd: Command) -> Result<(Vec, Vec)> { let (missing, errors) = dynamic_library::linux::find_missing(cmd)?; - Ok((missing.drain().map(|m| m.name).collect(), errors)) + Ok((missing.into_iter().map(|m| m.name).collect(), errors)) } #[cfg(target_os = "windows")]