From 87085bc48a7eb24fad3d30d6b935b7ca7de14315 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Wed, 11 Nov 2020 21:48:08 -0800 Subject: [PATCH] Change prepare_test_result to take reference (#297) Originally used move to avoid copying, but the copy is cheap in the normal case (no exceptions) and is more usable this way. --- src/agent/input-tester/src/crash_detector.rs | 1 + src/agent/input-tester/src/test_result/asan.rs | 2 +- src/agent/input-tester/src/test_result/mod.rs | 10 ++++++++-- .../input-tester/src/test_result/vcpp_debugger.rs | 2 +- .../input-tester/src/test_result/verifier_stop.rs | 9 +++++---- src/agent/input-tester/src/tester.rs | 10 +++++----- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/agent/input-tester/src/crash_detector.rs b/src/agent/input-tester/src/crash_detector.rs index 08cacfb64..7a3ffe540 100644 --- a/src/agent/input-tester/src/crash_detector.rs +++ b/src/agent/input-tester/src/crash_detector.rs @@ -42,6 +42,7 @@ use crate::{ }, }; +#[derive(Clone)] pub struct DebuggerResult { pub exceptions: Vec, pub exit_status: ExitStatus, diff --git a/src/agent/input-tester/src/test_result/asan.rs b/src/agent/input-tester/src/test_result/asan.rs index ae56c4621..7082ee28c 100644 --- a/src/agent/input-tester/src/test_result/asan.rs +++ b/src/agent/input-tester/src/test_result/asan.rs @@ -21,7 +21,7 @@ use winapi::{ /// An error detected by ASAN. /// /// These kinds are based on strings output by the lldb ASAN plugin, unrecognized errors should use `UnknownAsanError`. -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum AsanError { UnknownAsanError, HeapUseAfterFree, diff --git a/src/agent/input-tester/src/test_result/mod.rs b/src/agent/input-tester/src/test_result/mod.rs index e7209fc0a..23b2c0ec4 100644 --- a/src/agent/input-tester/src/test_result/mod.rs +++ b/src/agent/input-tester/src/test_result/mod.rs @@ -97,6 +97,7 @@ fn generic_exception(exception_record: &EXCEPTION_RECORD) -> Option From<&'a stack::DebugFunctionLocation> for DebugFunctionLocation { } /// A stack frame for reporting where an exception or other bug occurs. +#[derive(Clone)] pub enum DebugStackFrame { Frame { /// The name of the function (if available via symbols or exports) or possibly something else like a @@ -281,6 +285,7 @@ impl<'a> From<&'a stack::DebugStackFrame> for DebugStackFrame { } /// The details of an exception observed by the execution engine. +#[derive(Clone)] pub struct Exception { /// The win32 exception code. pub exception_code: u32, @@ -316,7 +321,7 @@ impl fmt::Display for Exception { } /// How did the program exit - normally (so we have a proper exit code) or was it terminated? -#[derive(Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum ExitStatus { /// The exit code returned from the process. Code(i32), @@ -363,6 +368,7 @@ impl fmt::Display for ExitStatus { } /// A fuzzer or execution engine sends this message to a back end to report the bugs found for a single input. +#[derive(Clone)] pub struct TestResult { /// The input filename that results in the bugs_found. pub input_file: String, @@ -401,7 +407,7 @@ impl TestResult { } /// This is a non-exhaustive list of exceptions that might be raised in a program. -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum ExceptionCode { UnknownExceptionCode, UnknownApplicationVerifierStop, diff --git a/src/agent/input-tester/src/test_result/vcpp_debugger.rs b/src/agent/input-tester/src/test_result/vcpp_debugger.rs index 5b91248db..13ae09b97 100644 --- a/src/agent/input-tester/src/test_result/vcpp_debugger.rs +++ b/src/agent/input-tester/src/test_result/vcpp_debugger.rs @@ -18,7 +18,7 @@ use winapi::{ }; /// Errors reported via the VC++ /RTC compiler flag, as defined in vctruntime\inc\rtcapi.h -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum VcppRtcError { UnknownRtcError, /// _RTC_CORRUPT_STACK (stack memory corrupted) diff --git a/src/agent/input-tester/src/test_result/verifier_stop.rs b/src/agent/input-tester/src/test_result/verifier_stop.rs index c4ea5c828..176124f34 100644 --- a/src/agent/input-tester/src/test_result/verifier_stop.rs +++ b/src/agent/input-tester/src/test_result/verifier_stop.rs @@ -114,7 +114,7 @@ fn exception_stop_from_u32(code: u32) -> ExceptionStop { } /// A bug detected by enabling `handles` in application verifier. -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum HandlesStop { InvalidHandleStop, InvalidTlsValue, @@ -125,7 +125,7 @@ pub enum HandlesStop { } /// A bug detected by enabling `heaps` in application verifier. -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum HeapStop { UnknownError, AccessViolation, @@ -150,7 +150,7 @@ pub enum HeapStop { } /// A bug detected by enabling `leak` in application verifier. -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum LeakStop { Allocation, Handle, @@ -165,7 +165,7 @@ pub enum LeakStop { /// /// We don't enable this option normally because it only detects first chance exceptions which are already /// reported and this option ends up reporting the same issue a second time with a different stack. -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum ExceptionStop { FirstChanceAccessViolationCode, } @@ -174,6 +174,7 @@ pub enum ExceptionStop { /// information in understanding the type of bug detected. /// /// This message encapsulates the most important kinds of bugs detected by application verifier when fuzzing. +#[derive(Copy, Clone)] pub enum VerifierStop { /// A bug detected by enabling `heaps` in application verifier. Heap(HeapStop), diff --git a/src/agent/input-tester/src/tester.rs b/src/agent/input-tester/src/tester.rs index 6931af51f..b6a48fed7 100644 --- a/src/agent/input-tester/src/tester.rs +++ b/src/agent/input-tester/src/tester.rs @@ -206,7 +206,7 @@ impl Tester { // and return a collection of results to possibly be reported. let mut test_results = vec![]; for result in results { - match self.prepare_test_result(result) { + match self.prepare_test_result(&result) { Ok(Some(result)) => test_results.push(result), Ok(None) => {} Err(e) => { @@ -228,7 +228,7 @@ impl Tester { let summary = Summary::from(&test_result.debugger_result); let mut results = vec![]; - if let Some(result) = self.prepare_test_result(test_result)? { + if let Some(result) = self.prepare_test_result(&test_result)? { results.push(result); } @@ -337,10 +337,10 @@ impl Tester { } } - pub fn prepare_test_result(&self, result: InputTestResult) -> Result> { + pub fn prepare_test_result(&self, result: &InputTestResult) -> Result> { if !result.debugger_result.any_crashes_or_timed_out() { return Ok(Some(new_test_result( - result.debugger_result, + result.debugger_result.clone(), &result.input_path, Path::new(""), ))); @@ -396,7 +396,7 @@ impl Tester { )); self.create_test_failure_artifacts(&logs_dir, &result, &copied_file)?; Ok(Some(new_test_result( - result.debugger_result, + result.debugger_result.clone(), &result.input_path, &logs_dir, )))