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

Commit 46bbe5b

Browse files
authored
Include all loader errors when failing (#3509)
Closes #2736. Include all errors from the loader transcript when looking for missing DLLs. This will help users to analyze the problem, as this information can include missing symbols, etc.
1 parent 2f2a649 commit 46bbe5b

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

src/agent/dynamic-library/src/bin/dynamic-library.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,35 @@ fn main() -> Result<()> {
3838
cmd.env("LD_LIBRARY_PATH", path);
3939
}
4040

41-
let missing = find_missing(cmd)?;
41+
let (missing, errors) = find_missing(cmd)?;
4242

4343
if missing.is_empty() {
4444
println!("no missing libraries");
4545
} else {
4646
for lib in missing {
4747
println!("missing library: {lib:x?}");
4848
}
49+
50+
if !errors.is_empty() {
51+
println!();
52+
53+
for err in errors {
54+
println!("error: {err}");
55+
}
56+
}
4957
}
5058

5159
Ok(())
5260
}
5361

5462
#[cfg(target_os = "linux")]
55-
fn find_missing(cmd: Command) -> Result<Vec<String>> {
56-
Ok(dynamic_library::linux::find_missing(cmd)?
57-
.drain()
58-
.map(|m| m.name)
59-
.collect())
63+
fn find_missing(cmd: Command) -> Result<(Vec<String>, Vec<String>)> {
64+
let (missing, errors) = dynamic_library::linux::find_missing(cmd)?;
65+
Ok((missing.into_iter().map(|m| m.name).collect(), errors))
6066
}
6167

6268
#[cfg(target_os = "windows")]
63-
fn find_missing(cmd: Command) -> Result<Vec<String>> {
64-
Ok(dynamic_library::windows::find_missing(cmd)?
65-
.into_iter()
66-
.map(|m| m.name)
67-
.collect())
69+
fn find_missing(cmd: Command) -> Result<(Vec<String>, Vec<String>)> {
70+
let (missing, errors) = dynamic_library::windows::find_missing(cmd)?;
71+
Ok((missing.into_iter().map(|m| m.name).collect(), errors))
6872
}

src/agent/dynamic-library/src/linux.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use regex::Regex;
1313

1414
const LD_LIBRARY_PATH: &str = "LD_LIBRARY_PATH";
1515

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

2628
if !missing_linked.is_empty() {
27-
return Ok(missing_linked);
29+
return Ok((missing_linked, Vec::new()));
2830
}
2931

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

37-
Ok(logs.missing())
39+
Ok((logs.missing(), Vec::new()))
3840
}
3941

4042
pub fn get_linked_library_logs(cmd: &Command) -> Result<std::process::Output, io::Error> {

src/agent/dynamic-library/src/windows.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ pub enum CheckDynamicLibrariesError {
2626

2727
pub fn find_missing(
2828
cmd: Command,
29-
) -> Result<Vec<MissingDynamicLibrary>, CheckDynamicLibrariesError> {
29+
) -> Result<(Vec<MissingDynamicLibrary>, Vec<String>), CheckDynamicLibrariesError> {
3030
let mut handler = LoaderSnapsHandler::default();
3131
setup_debugger(cmd, &mut handler)?;
32-
Ok(handler.missing_libraries())
32+
Ok((handler.missing_libraries(), handler.errors()))
3333
}
3434

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

274274
missing
275275
}
276+
277+
pub fn errors(&self) -> Vec<String> {
278+
self.debug_strings
279+
.iter()
280+
.filter(|text| text.contains("ERROR:"))
281+
.map(|text| text.to_owned())
282+
.collect()
283+
}
276284
}
277285

278286
impl DebugEventHandler for LoaderSnapsHandler {

src/agent/onefuzz/src/libfuzzer.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,25 +306,26 @@ impl LibFuzzer {
306306
if !result.status.success() {
307307
// To provide user-actionable errors, try to identify any missing shared libraries.
308308
match self.find_missing_libraries().await {
309-
Ok(missing) => {
309+
Ok((missing, errors)) => {
310310
if missing.is_empty() {
311-
bail!("fuzzer does not respond to '-help=1'. no missing shared libraries detected. output: {:?}", result);
311+
bail!("fuzzer does not respond to '-help=1'. no missing shared libraries detected. output: {result:?}");
312312
} else {
313313
let missing = missing.join(", ");
314+
let all_errors = errors.join("\n");
314315

315-
bail!("fuzzer does not respond to '-help=1'. missing shared libraries: {}. output: {:?}", missing, result);
316+
bail!("fuzzer does not respond to '-help=1'. missing shared libraries: {missing}. output: {result:?}. all errors: {all_errors}");
316317
}
317318
}
318319
Err(err) => {
319-
bail!("fuzzer does not respond to '-help=1'. additional error while checking for missing shared libraries: {}. output: {:?}", err, result);
320+
bail!("fuzzer does not respond to '-help=1'. additional error while checking for missing shared libraries: {err}. output: {result:?}");
320321
}
321322
}
322323
}
323324

324325
Ok(())
325326
}
326327

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

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

336-
let missing = tokio::task::spawn_blocking(blocking).await??;
337+
let (missing, errors) = tokio::task::spawn_blocking(blocking).await??;
338+
337339
let missing = missing.into_iter().map(|m| m.name).collect();
338340

339-
Ok(missing)
341+
Ok((missing, errors))
340342
}
341343

342344
pub fn fuzz(

src/proxy-manager/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)