Skip to content

Commit 1d7baff

Browse files
domenukkandreafioraldi
authored andcommitted
clippy fixes
1 parent 9b4fb23 commit 1d7baff

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

libafl_frida/src/asan_rt.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ impl AsanRuntime {
746746
}
747747

748748
/// Reset all allocations so that they can be reused for new allocation requests.
749+
#[allow(clippy::unused_self)]
749750
pub fn reset_allocations(&self) {
750751
Allocator::get().reset();
751752
}
@@ -759,11 +760,13 @@ impl AsanRuntime {
759760
}
760761
}
761762

763+
#[allow(clippy::unused_self)]
762764
pub fn errors(&mut self) -> &Option<AsanErrors> {
763765
unsafe { &ASAN_ERRORS }
764766
}
765767

766768
/// Make sure the specified memory is unpoisoned
769+
#[allow(clippy::unused_self)]
767770
pub fn unpoison(&self, address: usize, size: usize) {
768771
Allocator::get().map_shadow_for_region(address, address + size, true);
769772
}
@@ -779,6 +782,7 @@ impl AsanRuntime {
779782
}
780783

781784
/// Unpoison all the memory that is currently mapped with read/write permissions.
785+
#[allow(clippy::unused_self)]
782786
fn unpoison_all_existing_memory(&self) {
783787
let mut allocator = Allocator::get();
784788
walk_self_maps(&mut |start, end, permissions, _path| {
@@ -794,6 +798,7 @@ impl AsanRuntime {
794798

795799
/// Register the current thread with the runtime, implementing shadow memory for its stack and
796800
/// tls mappings.
801+
#[allow(clippy::unused_self)]
797802
pub fn register_thread(&self) {
798803
let mut allocator = Allocator::get();
799804
let (stack_start, stack_end) = Self::current_stack();
@@ -855,6 +860,7 @@ impl AsanRuntime {
855860

856861
/// Locate the target library and hook it's memory allocation functions
857862
#[cfg(unix)]
863+
#[allow(clippy::unused_self)]
858864
fn hook_library(&mut self, path: &str) {
859865
let target_lib = GotHookLibrary::new(path, false);
860866

@@ -925,6 +931,8 @@ impl AsanRuntime {
925931
}
926932
}
927933

934+
#[allow(clippy::cast_sign_loss)] // for displacement
935+
#[allow(clippy::too_many_lines)]
928936
extern "C" fn handle_trap(&mut self) {
929937
let mut actual_pc = self.regs[31];
930938
actual_pc = match self.stalked_addresses.get(&actual_pc) {
@@ -990,6 +998,7 @@ impl AsanRuntime {
990998
base_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16;
991999
}
9921000

1001+
#[allow(clippy::clippy::cast_possible_wrap)]
9931002
let mut fault_address =
9941003
(self.regs[base_reg as usize] as isize + displacement as isize) as usize;
9951004

@@ -1043,6 +1052,7 @@ impl AsanRuntime {
10431052
}
10441053
} else {
10451054
let mut allocator = Allocator::get();
1055+
#[allow(clippy::option_if_let_else)]
10461056
if let Some(metadata) =
10471057
allocator.find_metadata(fault_address, self.regs[base_reg as usize])
10481058
{
@@ -1076,6 +1086,7 @@ impl AsanRuntime {
10761086
self.report_error(error);
10771087
}
10781088

1089+
#[allow(clippy::too_many_lines)]
10791090
fn report_error(&mut self, error: AsanError) {
10801091
unsafe {
10811092
ASAN_ERRORS.as_mut().unwrap().errors.push(error.clone());
@@ -1356,6 +1367,7 @@ impl AsanRuntime {
13561367
}
13571368
}
13581369

1370+
#[allow(clippy::unused_self)]
13591371
fn generate_shadow_check_blob(&mut self, bit: u32) -> Box<[u8]> {
13601372
let shadow_bit = Allocator::get().shadow_bit as u32;
13611373
macro_rules! shadow_check {
@@ -1386,6 +1398,7 @@ impl AsanRuntime {
13861398
ops_vec[..ops_vec.len() - 4].to_vec().into_boxed_slice()
13871399
}
13881400

1401+
#[allow(clippy::unused_self)]
13891402
fn generate_shadow_check_exact_blob(&mut self, val: u32) -> Box<[u8]> {
13901403
let shadow_bit = Allocator::get().shadow_bit as u32;
13911404
macro_rules! shadow_check_exact {
@@ -1422,6 +1435,8 @@ impl AsanRuntime {
14221435
///
14231436
/// Generate the instrumentation blobs for the current arch.
14241437
#[allow(clippy::similar_names)] // We allow things like dword and qword
1438+
#[allow(clippy::cast_possible_wrap)]
1439+
#[allow(clippy::too_many_lines)]
14251440
fn generate_instrumentation_blobs(&mut self) {
14261441
let mut ops_report = dynasmrt::VecAssembler::<dynasmrt::aarch64::Aarch64Relocation>::new(0);
14271442
dynasm!(ops_report
@@ -1522,7 +1537,7 @@ impl AsanRuntime {
15221537
//offset r30 (x30) at cfa-8
15231538
//offset r29 (x29) at cfa-16
15241539
; .dword 0x1d0c4c00
1525-
; .dword 0x9d029e10 as u32 as i32
1540+
; .dword 0x9d029e10u32 as i32
15261541
; .dword 0x04
15271542
// empty next FDE:
15281543
; .dword 0x0

libafl_frida/src/helper.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
378378
Aarch64Register::X0,
379379
Aarch64Register::X1,
380380
Aarch64Register::Sp,
381-
-(16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32) as i64,
381+
-(16 + redzone_size) as i64,
382382
IndexMode::PreAdjust,
383383
);
384384

@@ -459,7 +459,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
459459

460460
let displacement = displacement
461461
+ if basereg == Aarch64Register::Sp {
462-
16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32
462+
16 + redzone_size
463463
} else {
464464
0
465465
};
@@ -536,7 +536,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
536536
Aarch64Register::X0,
537537
Aarch64Register::X1,
538538
Aarch64Register::Sp,
539-
16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i64,
539+
16 + redzone_size as i64,
540540
IndexMode::PostAdjust,
541541
));
542542
}
@@ -662,6 +662,8 @@ impl<'a> FridaInstrumentationHelper<'a> {
662662
#[inline]
663663
fn emit_coverage_mapping(&mut self, address: u64, output: &StalkerOutput) {
664664
let writer = output.writer();
665+
#[allow(clippy::cast_possible_wrap)] // gum redzone size is u32, we need an offset as i32.
666+
let redzone_size = frida_gum_sys::GUM_RED_ZONE_SIZE as i32;
665667
if self.current_log_impl == 0
666668
|| !writer.can_branch_directly_to(self.current_log_impl)
667669
|| !writer.can_branch_directly_between(writer.pc() + 128, self.current_log_impl)
@@ -686,31 +688,23 @@ impl<'a> FridaInstrumentationHelper<'a> {
686688
#[cfg(target_arch = "x86_64")]
687689
{
688690
println!("here");
689-
writer.put_lea_reg_reg_offset(
690-
X86Register::Rsp,
691-
X86Register::Rsp,
692-
-(frida_gum_sys::GUM_RED_ZONE_SIZE as i32),
693-
);
691+
writer.put_lea_reg_reg_offset(X86Register::Rsp, X86Register::Rsp, -(redzone_size));
694692
writer.put_push_reg(X86Register::Rdi);
695693
writer.put_mov_reg_address(
696694
X86Register::Rdi,
697695
((address >> 4) ^ (address << 8)) & (MAP_SIZE - 1) as u64,
698696
);
699697
writer.put_call_address(self.current_log_impl);
700698
writer.put_pop_reg(X86Register::Rdi);
701-
writer.put_lea_reg_reg_offset(
702-
X86Register::Rsp,
703-
X86Register::Rsp,
704-
frida_gum_sys::GUM_RED_ZONE_SIZE as i32,
705-
);
699+
writer.put_lea_reg_reg_offset(X86Register::Rsp, X86Register::Rsp, redzone_size);
706700
}
707701
#[cfg(target_arch = "aarch64")]
708702
{
709703
writer.put_stp_reg_reg_reg_offset(
710704
Aarch64Register::Lr,
711705
Aarch64Register::X0,
712706
Aarch64Register::Sp,
713-
-(16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32) as i64,
707+
-(16 + redzone_size) as i64,
714708
IndexMode::PreAdjust,
715709
);
716710
writer.put_ldr_reg_u64(
@@ -722,7 +716,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
722716
Aarch64Register::Lr,
723717
Aarch64Register::X0,
724718
Aarch64Register::Sp,
725-
16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i64,
719+
16 + redzone_size as i64,
726720
IndexMode::PostAdjust,
727721
);
728722
}

0 commit comments

Comments
 (0)