From 3c503f68709797f50539e2b27416c7ae61870d30 Mon Sep 17 00:00:00 2001 From: Matthew Jurenka Date: Mon, 30 May 2022 23:03:29 -0700 Subject: [PATCH] removed global logging fuzz test --- .github/workflows/mayhem.yml | 7 -- Dockerfile | 1 - fuzz/Cargo.toml | 6 -- fuzz/fuzz_targets/global_logging.rs | 105 -------------------------- mayhemfiles/Mayhemfile_Global_Logging | 6 -- 5 files changed, 125 deletions(-) delete mode 100644 fuzz/fuzz_targets/global_logging.rs delete mode 100644 mayhemfiles/Mayhemfile_Global_Logging diff --git a/.github/workflows/mayhem.yml b/.github/workflows/mayhem.yml index 0e6ab60..6d82697 100644 --- a/.github/workflows/mayhem.yml +++ b/.github/workflows/mayhem.yml @@ -53,13 +53,6 @@ jobs: args: --file mayhemfiles/Mayhemfile_Channels --image ${{ steps.meta.outputs.tags }} sarif-output: sarif - - name: Start analysis of Global Logging - uses: ForAllSecure/mcode-action@v1 - with: - mayhem-token: ${{ secrets.MAYHEM_TOKEN }} - args: --file mayhemfiles/Mayhemfile_Global_Logging --image ${{ steps.meta.outputs.tags }} - sarif-output: sarif - - name: Upload SARIF file(s) uses: github/codeql-action/upload-sarif@v1 with: diff --git a/Dockerfile b/Dockerfile index defc20e..dd869c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,3 @@ FROM --platform=linux/amd64 rustlang/rust:nightly ## TODO: Change COPY --from=builder /fern/fuzz/target/x86_64-unknown-linux-gnu/release/channels / -COPY --from=builder /fern/fuzz/target/x86_64-unknown-linux-gnu/release/global_logging / diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 080b434..9c41131 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -24,9 +24,3 @@ name = "channels" path = "fuzz_targets/channels.rs" test = false doc = false - -[[bin]] -name = "global_logging" -path = "fuzz_targets/global_logging.rs" -test = false -doc = false diff --git a/fuzz/fuzz_targets/global_logging.rs b/fuzz/fuzz_targets/global_logging.rs deleted file mode 100644 index fc87fc5..0000000 --- a/fuzz/fuzz_targets/global_logging.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![no_main] -use libfuzzer_sys::fuzz_target; - -use std::sync::{Arc, Mutex}; - -use log::{debug, error, info, trace, warn}; - -/// Custom logger built to verify our exact test case. -struct LogVerify { - info: bool, - warn: bool, - error: bool, -} - -impl LogVerify { - fn new() -> Self { - LogVerify { - info: false, - warn: false, - error: false, - } - } - fn log(&mut self, record: &log::Record) { - let formatted_message = format!("{}", record.args()); - if formatted_message.starts_with("[INFO] ") { - assert_eq!(self.info, false, "expected only one info message"); - self.info = true; - } else if formatted_message.starts_with("[WARN] ") { - assert_eq!(self.warn, false, "expected only one warn message"); - self.warn = true; - } else if formatted_message.starts_with("[ERROR] ") { - assert_eq!(self.error, false, "expected only one error message"); - self.error = true; - } else { - panic!(); - } - } -} -/// Wrapper for our verification which acts as the actual logger. -#[derive(Clone)] -struct LogVerifyWrapper(Arc>); - -impl LogVerifyWrapper { - fn new() -> Self { - LogVerifyWrapper(Arc::new(Mutex::new(LogVerify::new()))) - } - - fn cloned_boxed_logger(&self) -> Box { - Box::new(self.clone()) - } -} - -impl log::Log for LogVerifyWrapper { - fn enabled(&self, _: &log::Metadata) -> bool { - true - } - fn log(&self, record: &log::Record) { - self.0.lock().unwrap().log(record); - } - fn flush(&self) {} -} - -fuzz_target!(|data: &[u8]| { - match std::str::from_utf8(data) { - Ok(s) => { - let verify = LogVerifyWrapper::new(); - - // Create a basic logger configuration - fern::Dispatch::new() - .format(|out, msg, record| out.finish( - format_args!("[{}] {}", record.level(), msg) - )) - // Only log messages Info and above - .level(log::LevelFilter::Info) - // Output to our verification logger for verification - .chain(verify.cloned_boxed_logger()) - .apply() - .expect("Failed to initialize logger: global logger already set!"); - - trace!("{}", s); - debug!("{}", s); - info!("{}", s); - warn!("{}", s); - error!("{}", s); - - // ensure all buffers are flushed. - log::logger().flush(); - - let verify_acquired = verify.0.lock().unwrap(); - assert_eq!( - verify_acquired.info, true, - "expected info message to be received" - ); - assert_eq!( - verify_acquired.warn, true, - "expected warn message to be received" - ); - assert_eq!( - verify_acquired.error, true, - "expected error message to be received" - ); - }, - _ => {}, - } -}); diff --git a/mayhemfiles/Mayhemfile_Global_Logging b/mayhemfiles/Mayhemfile_Global_Logging deleted file mode 100644 index 6fb0e93..0000000 --- a/mayhemfiles/Mayhemfile_Global_Logging +++ /dev/null @@ -1,6 +0,0 @@ -project: fern -target: global-logging -duration: 90 - -cmds: - - cmd: /global_logging