From 1d7baffea91eb881920f2b5d8fb03aac6ddc8513 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Wed, 5 May 2021 13:15:59 +0200 Subject: [PATCH] clippy fixes --- libafl_frida/src/asan_rt.rs | 17 ++++++++++++++++- libafl_frida/src/helper.rs | 24 +++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/libafl_frida/src/asan_rt.rs b/libafl_frida/src/asan_rt.rs index 12d957933d..cb6f46c17b 100644 --- a/libafl_frida/src/asan_rt.rs +++ b/libafl_frida/src/asan_rt.rs @@ -746,6 +746,7 @@ impl AsanRuntime { } /// Reset all allocations so that they can be reused for new allocation requests. + #[allow(clippy::unused_self)] pub fn reset_allocations(&self) { Allocator::get().reset(); } @@ -759,11 +760,13 @@ impl AsanRuntime { } } + #[allow(clippy::unused_self)] pub fn errors(&mut self) -> &Option { unsafe { &ASAN_ERRORS } } /// Make sure the specified memory is unpoisoned + #[allow(clippy::unused_self)] pub fn unpoison(&self, address: usize, size: usize) { Allocator::get().map_shadow_for_region(address, address + size, true); } @@ -779,6 +782,7 @@ impl AsanRuntime { } /// Unpoison all the memory that is currently mapped with read/write permissions. + #[allow(clippy::unused_self)] fn unpoison_all_existing_memory(&self) { let mut allocator = Allocator::get(); walk_self_maps(&mut |start, end, permissions, _path| { @@ -794,6 +798,7 @@ impl AsanRuntime { /// Register the current thread with the runtime, implementing shadow memory for its stack and /// tls mappings. + #[allow(clippy::unused_self)] pub fn register_thread(&self) { let mut allocator = Allocator::get(); let (stack_start, stack_end) = Self::current_stack(); @@ -855,6 +860,7 @@ impl AsanRuntime { /// Locate the target library and hook it's memory allocation functions #[cfg(unix)] + #[allow(clippy::unused_self)] fn hook_library(&mut self, path: &str) { let target_lib = GotHookLibrary::new(path, false); @@ -925,6 +931,8 @@ impl AsanRuntime { } } + #[allow(clippy::cast_sign_loss)] // for displacement + #[allow(clippy::too_many_lines)] extern "C" fn handle_trap(&mut self) { let mut actual_pc = self.regs[31]; actual_pc = match self.stalked_addresses.get(&actual_pc) { @@ -990,6 +998,7 @@ impl AsanRuntime { base_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16; } + #[allow(clippy::clippy::cast_possible_wrap)] let mut fault_address = (self.regs[base_reg as usize] as isize + displacement as isize) as usize; @@ -1043,6 +1052,7 @@ impl AsanRuntime { } } else { let mut allocator = Allocator::get(); + #[allow(clippy::option_if_let_else)] if let Some(metadata) = allocator.find_metadata(fault_address, self.regs[base_reg as usize]) { @@ -1076,6 +1086,7 @@ impl AsanRuntime { self.report_error(error); } + #[allow(clippy::too_many_lines)] fn report_error(&mut self, error: AsanError) { unsafe { ASAN_ERRORS.as_mut().unwrap().errors.push(error.clone()); @@ -1356,6 +1367,7 @@ impl AsanRuntime { } } + #[allow(clippy::unused_self)] fn generate_shadow_check_blob(&mut self, bit: u32) -> Box<[u8]> { let shadow_bit = Allocator::get().shadow_bit as u32; macro_rules! shadow_check { @@ -1386,6 +1398,7 @@ impl AsanRuntime { ops_vec[..ops_vec.len() - 4].to_vec().into_boxed_slice() } + #[allow(clippy::unused_self)] fn generate_shadow_check_exact_blob(&mut self, val: u32) -> Box<[u8]> { let shadow_bit = Allocator::get().shadow_bit as u32; macro_rules! shadow_check_exact { @@ -1422,6 +1435,8 @@ impl AsanRuntime { /// /// Generate the instrumentation blobs for the current arch. #[allow(clippy::similar_names)] // We allow things like dword and qword + #[allow(clippy::cast_possible_wrap)] + #[allow(clippy::too_many_lines)] fn generate_instrumentation_blobs(&mut self) { let mut ops_report = dynasmrt::VecAssembler::::new(0); dynasm!(ops_report @@ -1522,7 +1537,7 @@ impl AsanRuntime { //offset r30 (x30) at cfa-8 //offset r29 (x29) at cfa-16 ; .dword 0x1d0c4c00 - ; .dword 0x9d029e10 as u32 as i32 + ; .dword 0x9d029e10u32 as i32 ; .dword 0x04 // empty next FDE: ; .dword 0x0 diff --git a/libafl_frida/src/helper.rs b/libafl_frida/src/helper.rs index 078c82038f..148f85495e 100644 --- a/libafl_frida/src/helper.rs +++ b/libafl_frida/src/helper.rs @@ -378,7 +378,7 @@ impl<'a> FridaInstrumentationHelper<'a> { Aarch64Register::X0, Aarch64Register::X1, Aarch64Register::Sp, - -(16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32) as i64, + -(16 + redzone_size) as i64, IndexMode::PreAdjust, ); @@ -459,7 +459,7 @@ impl<'a> FridaInstrumentationHelper<'a> { let displacement = displacement + if basereg == Aarch64Register::Sp { - 16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32 + 16 + redzone_size } else { 0 }; @@ -536,7 +536,7 @@ impl<'a> FridaInstrumentationHelper<'a> { Aarch64Register::X0, Aarch64Register::X1, Aarch64Register::Sp, - 16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i64, + 16 + redzone_size as i64, IndexMode::PostAdjust, )); } @@ -662,6 +662,8 @@ impl<'a> FridaInstrumentationHelper<'a> { #[inline] fn emit_coverage_mapping(&mut self, address: u64, output: &StalkerOutput) { let writer = output.writer(); + #[allow(clippy::cast_possible_wrap)] // gum redzone size is u32, we need an offset as i32. + let redzone_size = frida_gum_sys::GUM_RED_ZONE_SIZE as i32; if self.current_log_impl == 0 || !writer.can_branch_directly_to(self.current_log_impl) || !writer.can_branch_directly_between(writer.pc() + 128, self.current_log_impl) @@ -686,11 +688,7 @@ impl<'a> FridaInstrumentationHelper<'a> { #[cfg(target_arch = "x86_64")] { println!("here"); - writer.put_lea_reg_reg_offset( - X86Register::Rsp, - X86Register::Rsp, - -(frida_gum_sys::GUM_RED_ZONE_SIZE as i32), - ); + writer.put_lea_reg_reg_offset(X86Register::Rsp, X86Register::Rsp, -(redzone_size)); writer.put_push_reg(X86Register::Rdi); writer.put_mov_reg_address( X86Register::Rdi, @@ -698,11 +696,7 @@ impl<'a> FridaInstrumentationHelper<'a> { ); writer.put_call_address(self.current_log_impl); writer.put_pop_reg(X86Register::Rdi); - writer.put_lea_reg_reg_offset( - X86Register::Rsp, - X86Register::Rsp, - frida_gum_sys::GUM_RED_ZONE_SIZE as i32, - ); + writer.put_lea_reg_reg_offset(X86Register::Rsp, X86Register::Rsp, redzone_size); } #[cfg(target_arch = "aarch64")] { @@ -710,7 +704,7 @@ impl<'a> FridaInstrumentationHelper<'a> { Aarch64Register::Lr, Aarch64Register::X0, Aarch64Register::Sp, - -(16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32) as i64, + -(16 + redzone_size) as i64, IndexMode::PreAdjust, ); writer.put_ldr_reg_u64( @@ -722,7 +716,7 @@ impl<'a> FridaInstrumentationHelper<'a> { Aarch64Register::Lr, Aarch64Register::X0, Aarch64Register::Sp, - 16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i64, + 16 + redzone_size as i64, IndexMode::PostAdjust, ); }