Skip to content

Commit 7cd9954

Browse files
domenukkandreafioraldi
authored andcommitted
Clippy fixes (#92)
* more docs * more docs: * more docu * more docu * finished docs * cleaned up markup * must_use tags added * more docs * swapped if/else, as per clippy * more docu, less clippy * more fixes
1 parent ed91691 commit 7cd9954

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

libafl/src/bolts/llmp.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,10 @@ where
803803
panic!("PROGRAM ABORT : BUG: EOP does not fit in page! page {:?}, size_current {:?}, size_total {:?}", page,
804804
ptr::addr_of!((*page).size_used), ptr::addr_of!((*page).size_total));
805805
}
806-
let mut ret: *mut LlmpMsg = if !last_msg.is_null() {
807-
llmp_next_msg_ptr_checked(&mut map, last_msg, EOP_MSG_SIZE)?
808-
} else {
806+
let mut ret: *mut LlmpMsg = if last_msg.is_null() {
809807
(*page).messages.as_mut_ptr()
808+
} else {
809+
llmp_next_msg_ptr_checked(&mut map, last_msg, EOP_MSG_SIZE)?
810810
};
811811
if (*ret).tag == LLMP_TAG_UNINITIALIZED {
812812
panic!("Did not call send() on last message!");
@@ -815,10 +815,10 @@ where
815815

816816
// We don't need to pad the EOP message: it'll always be the last in this page.
817817
(*ret).buf_len_padded = (*ret).buf_len;
818-
(*ret).message_id = if !last_msg.is_null() {
819-
(*last_msg).message_id + 1
820-
} else {
818+
(*ret).message_id = if last_msg.is_null() {
821819
1
820+
} else {
821+
(*last_msg).message_id + 1
822822
};
823823
(*ret).tag = LLMP_TAG_END_OF_PAGE;
824824
(*page).size_used += EOP_MSG_SIZE;
@@ -880,10 +880,7 @@ where
880880
} else {
881881
(*last_msg).message_id + 1
882882
}
883-
} else if (*page).current_msg_id != (*last_msg).message_id {
884-
/* Oops, wrong usage! */
885-
panic!("BUG: The current message never got commited using send! (page->current_msg_id {:?}, last_msg->message_id: {})", ptr::addr_of!((*page).current_msg_id), (*last_msg).message_id);
886-
} else {
883+
} else if (*page).current_msg_id == (*last_msg).message_id {
887884
buf_len_padded = complete_msg_size - size_of::<LlmpMsg>();
888885
/* DBG("XXX ret %p id %u buf_len_padded %lu complete_msg_size %lu\n", ret, ret->message_id, buf_len_padded,
889886
* complete_msg_size); */
@@ -905,6 +902,9 @@ where
905902
}
906903
};
907904
(*ret).message_id = (*last_msg).message_id + 1
905+
} else {
906+
/* Oops, wrong usage! */
907+
panic!("BUG: The current message never got committed using send! (page->current_msg_id {:?}, last_msg->message_id: {})", ptr::addr_of!((*page).current_msg_id), (*last_msg).message_id);
908908
}
909909

910910
/* The beginning of our message should be messages + size_used, else nobody

libafl/src/executors/inprocess.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,39 @@ mod unix_signal_handler {
398398

399399
#[cfg(feature = "std")]
400400
println!("Crashed with {}", _signal);
401-
if !data.current_input_ptr.is_null() {
401+
if data.current_input_ptr.is_null() {
402+
#[cfg(feature = "std")]
403+
{
404+
println!("Double crash\n");
405+
#[cfg(target_os = "android")]
406+
let si_addr =
407+
{ ((_info._pad[0] as usize) | ((_info._pad[1] as usize) << 32)) as usize };
408+
#[cfg(not(target_os = "android"))]
409+
let si_addr = { _info.si_addr() as usize };
410+
411+
println!(
412+
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
413+
si_addr
414+
);
415+
}
416+
// let's yolo-cat the maps for debugging, if possible.
417+
#[cfg(all(target_os = "linux", feature = "std"))]
418+
match std::fs::read_to_string("/proc/self/maps") {
419+
Ok(maps) => println!("maps:\n{}", maps),
420+
Err(e) => println!("Couldn't load mappings: {:?}", e),
421+
};
422+
#[cfg(feature = "std")]
423+
{
424+
println!("Type QUIT to restart the child");
425+
let mut line = String::new();
426+
while line.trim() != "QUIT" {
427+
std::io::stdin().read_line(&mut line).unwrap();
428+
}
429+
}
430+
431+
// TODO tell the parent to not restart
432+
libc::_exit(1);
433+
} else {
402434
let state = (data.state_ptr as *mut S).as_mut().unwrap();
403435
let event_mgr = (data.event_mgr_ptr as *mut EM).as_mut().unwrap();
404436
let observers = (data.observers_ptr as *const OT).as_ref().unwrap();
@@ -484,38 +516,6 @@ mod unix_signal_handler {
484516
#[cfg(feature = "std")]
485517
println!("Bye!");
486518

487-
libc::_exit(1);
488-
} else {
489-
#[cfg(feature = "std")]
490-
{
491-
println!("Double crash\n");
492-
#[cfg(target_os = "android")]
493-
let si_addr =
494-
{ ((_info._pad[0] as usize) | ((_info._pad[1] as usize) << 32)) as usize };
495-
#[cfg(not(target_os = "android"))]
496-
let si_addr = { _info.si_addr() as usize };
497-
498-
println!(
499-
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
500-
si_addr
501-
);
502-
}
503-
// let's yolo-cat the maps for debugging, if possible.
504-
#[cfg(all(target_os = "linux", feature = "std"))]
505-
match std::fs::read_to_string("/proc/self/maps") {
506-
Ok(maps) => println!("maps:\n{}", maps),
507-
Err(e) => println!("Couldn't load mappings: {:?}", e),
508-
};
509-
#[cfg(feature = "std")]
510-
{
511-
println!("Type QUIT to restart the child");
512-
let mut line = String::new();
513-
while line.trim() != "QUIT" {
514-
std::io::stdin().read_line(&mut line).unwrap();
515-
}
516-
}
517-
518-
// TODO tell the parent to not restart
519519
libc::_exit(1);
520520
}
521521
}

libafl/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,12 @@ pub fn find_mapping_for_address(address: usize) -> Result<(usize, usize, String,
506506
}
507507
});
508508

509-
if result.0 != 0 {
510-
Ok(result)
511-
} else {
509+
if result.0 == 0 {
512510
Err(Error::Unknown(
513511
"Couldn't find a mapping for this address".to_string(),
514512
))
513+
} else {
514+
Ok(result)
515515
}
516516
}
517517

libafl_frida/src/asan_rt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,9 @@ impl AsanRuntime {
10451045
let mut fault_address =
10461046
(self.regs[base_reg as usize] as isize + displacement as isize) as usize;
10471047

1048-
if index_reg != 0 {
1048+
if index_reg == 0 {
1049+
index_reg = 0xffff
1050+
} else {
10491051
if capstone::arch::arm64::Arm64Reg::ARM64_REG_X0 as u16 <= index_reg
10501052
&& index_reg <= capstone::arch::arm64::Arm64Reg::ARM64_REG_X28 as u16
10511053
{
@@ -1070,8 +1072,6 @@ impl AsanRuntime {
10701072
index_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16;
10711073
}
10721074
fault_address += self.regs[index_reg as usize] as usize;
1073-
} else {
1074-
index_reg = 0xffff
10751075
}
10761076

10771077
let backtrace = Backtrace::new();
@@ -1783,11 +1783,11 @@ where
17831783
match observer.errors() {
17841784
None => Ok(false),
17851785
Some(errors) => {
1786-
if !errors.errors.is_empty() {
1786+
if errors.errors.is_empty() {
1787+
Ok(false)
1788+
} else {
17871789
self.errors = Some(errors.clone());
17881790
Ok(true)
1789-
} else {
1790-
Ok(false)
17911791
}
17921792
}
17931793
}

0 commit comments

Comments
 (0)