diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index a6fd669bf6..9f5735816e 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -10,6 +10,27 @@ env: CARGO_TERM_COLOR: always jobs: + lint: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Cache cargo registry + uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: clippy-cargo-${{ hashFiles('**/Cargo.toml') }} + - name: Add clippy + run: rustup component add clippy + - name: Run clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all ubuntu: runs-on: ubuntu-latest steps: diff --git a/Cargo.toml b/Cargo.toml index 1c364ac8eb..77ae433219 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,3 @@ - [profile.release] lto = true codegen-units = 1 diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index 285907f1b1..bb71eeb574 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -1018,7 +1018,7 @@ where /* We can reuse the map mem space, no need to free and calloc. However, the pageinfo points to the map we're about to unmap. Clone the contents first to be safe (probably fine in rust eitner way). */ - let pageinfo_cpy = (*pageinfo).clone(); + let pageinfo_cpy = *pageinfo; // Mark the old page save to unmap, in case we didn't so earlier. ptr::write_volatile(&mut (*page).save_to_unmap, 1); @@ -1434,7 +1434,7 @@ where // to read from the initial map id. let client_out_map_mem = &self.llmp_out.out_maps.first().unwrap().shmem; - let broadcast_str_initial = client_out_map_mem.shm_slice().clone(); + let broadcast_str_initial = *client_out_map_mem.shm_slice(); let llmp_tcp_id = self.llmp_clients.len() as u32; diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index a4d55d0100..2d832da7e9 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -370,7 +370,7 @@ pub mod unix_shmem { // Not set or not initialized; return; } - (*shm).shm_str[0 as usize] = 0u8; + (*shm).shm_str[0_usize] = 0u8; shmctl((*shm).shm_id, 0 as c_int, ptr::null_mut()); (*shm).map = ptr::null_mut(); } diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 7606284edf..fa42f0da9a 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -223,10 +223,7 @@ mod unix_signal_handler { use core::ptr; use libc::{c_void, siginfo_t}; #[cfg(feature = "std")] - use std::{ - fs, - io::{stdout, Write}, - }; + use std::io::{stdout, Write}; use crate::{ bolts::os::unix_signals::{Handler, Signal}, @@ -443,7 +440,7 @@ mod unix_signal_handler { } // let's yolo-cat the maps for debugging, if possible. #[cfg(all(target_os = "linux", feature = "std"))] - match fs::read_to_string("/proc/self/maps") { + match std::fs::read_to_string("/proc/self/maps") { Ok(maps) => println!("maps:\n{}", maps), Err(e) => println!("Couldn't load mappings: {:?}", e), }; diff --git a/libafl/src/mutators/mutations.rs b/libafl/src/mutators/mutations.rs index dd8946eec9..041c4b057a 100644 --- a/libafl/src/mutators/mutations.rs +++ b/libafl/src/mutators/mutations.rs @@ -752,13 +752,13 @@ where // Converts a hex u8 to its u8 value: 'A' -> 10 etc. fn from_hex(hex: u8) -> Result { - if hex >= 48 && hex <= 57 { + if (48..=57).contains(&hex) { return Ok(hex - 48); } - if hex >= 65 && hex <= 70 { + if (65..=70).contains(&hex) { return Ok(hex - 55); } - if hex >= 97 && hex <= 102 { + if (97..=102).contains(&hex) { return Ok(hex - 87); } Err(Error::IllegalArgument("".to_owned())) @@ -781,17 +781,15 @@ pub fn str_decode(item: &str) -> Result, Error> { decoded += from_hex(c)?; token.push(decoded); take_next_two = 0; - } else { - if c != backslash || take_next { - if take_next && (c == 120 || c == 88) { - take_next_two = 1; - } else { - token.push(c); - } - take_next = false; + } else if c != backslash || take_next { + if take_next && (c == 120 || c == 88) { + take_next_two = 1; } else { - take_next = true; + token.push(c); } + take_next = false; + } else { + take_next = true; } }