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
This commit is contained in:
Dominik Maier 2021-05-06 04:26:01 +02:00 committed by Andrea Fioraldi
parent ed9169119e
commit 7cd99543bb
4 changed files with 52 additions and 52 deletions

View File

@ -803,10 +803,10 @@ where
panic!("PROGRAM ABORT : BUG: EOP does not fit in page! page {:?}, size_current {:?}, size_total {:?}", page, panic!("PROGRAM ABORT : BUG: EOP does not fit in page! page {:?}, size_current {:?}, size_total {:?}", page,
ptr::addr_of!((*page).size_used), ptr::addr_of!((*page).size_total)); ptr::addr_of!((*page).size_used), ptr::addr_of!((*page).size_total));
} }
let mut ret: *mut LlmpMsg = if !last_msg.is_null() { let mut ret: *mut LlmpMsg = if last_msg.is_null() {
llmp_next_msg_ptr_checked(&mut map, last_msg, EOP_MSG_SIZE)?
} else {
(*page).messages.as_mut_ptr() (*page).messages.as_mut_ptr()
} else {
llmp_next_msg_ptr_checked(&mut map, last_msg, EOP_MSG_SIZE)?
}; };
if (*ret).tag == LLMP_TAG_UNINITIALIZED { if (*ret).tag == LLMP_TAG_UNINITIALIZED {
panic!("Did not call send() on last message!"); panic!("Did not call send() on last message!");
@ -815,10 +815,10 @@ where
// We don't need to pad the EOP message: it'll always be the last in this page. // We don't need to pad the EOP message: it'll always be the last in this page.
(*ret).buf_len_padded = (*ret).buf_len; (*ret).buf_len_padded = (*ret).buf_len;
(*ret).message_id = if !last_msg.is_null() { (*ret).message_id = if last_msg.is_null() {
(*last_msg).message_id + 1
} else {
1 1
} else {
(*last_msg).message_id + 1
}; };
(*ret).tag = LLMP_TAG_END_OF_PAGE; (*ret).tag = LLMP_TAG_END_OF_PAGE;
(*page).size_used += EOP_MSG_SIZE; (*page).size_used += EOP_MSG_SIZE;
@ -880,10 +880,7 @@ where
} else { } else {
(*last_msg).message_id + 1 (*last_msg).message_id + 1
} }
} else if (*page).current_msg_id != (*last_msg).message_id { } else if (*page).current_msg_id == (*last_msg).message_id {
/* Oops, wrong usage! */
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);
} else {
buf_len_padded = complete_msg_size - size_of::<LlmpMsg>(); buf_len_padded = complete_msg_size - size_of::<LlmpMsg>();
/* DBG("XXX ret %p id %u buf_len_padded %lu complete_msg_size %lu\n", ret, ret->message_id, buf_len_padded, /* DBG("XXX ret %p id %u buf_len_padded %lu complete_msg_size %lu\n", ret, ret->message_id, buf_len_padded,
* complete_msg_size); */ * complete_msg_size); */
@ -905,6 +902,9 @@ where
} }
}; };
(*ret).message_id = (*last_msg).message_id + 1 (*ret).message_id = (*last_msg).message_id + 1
} else {
/* Oops, wrong usage! */
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);
} }
/* The beginning of our message should be messages + size_used, else nobody /* The beginning of our message should be messages + size_used, else nobody

View File

@ -398,7 +398,39 @@ mod unix_signal_handler {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Crashed with {}", _signal); println!("Crashed with {}", _signal);
if !data.current_input_ptr.is_null() { if data.current_input_ptr.is_null() {
#[cfg(feature = "std")]
{
println!("Double crash\n");
#[cfg(target_os = "android")]
let si_addr =
{ ((_info._pad[0] as usize) | ((_info._pad[1] as usize) << 32)) as usize };
#[cfg(not(target_os = "android"))]
let si_addr = { _info.si_addr() as usize };
println!(
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
si_addr
);
}
// let's yolo-cat the maps for debugging, if possible.
#[cfg(all(target_os = "linux", feature = "std"))]
match std::fs::read_to_string("/proc/self/maps") {
Ok(maps) => println!("maps:\n{}", maps),
Err(e) => println!("Couldn't load mappings: {:?}", e),
};
#[cfg(feature = "std")]
{
println!("Type QUIT to restart the child");
let mut line = String::new();
while line.trim() != "QUIT" {
std::io::stdin().read_line(&mut line).unwrap();
}
}
// TODO tell the parent to not restart
libc::_exit(1);
} else {
let state = (data.state_ptr as *mut S).as_mut().unwrap(); let state = (data.state_ptr as *mut S).as_mut().unwrap();
let event_mgr = (data.event_mgr_ptr as *mut EM).as_mut().unwrap(); let event_mgr = (data.event_mgr_ptr as *mut EM).as_mut().unwrap();
let observers = (data.observers_ptr as *const OT).as_ref().unwrap(); let observers = (data.observers_ptr as *const OT).as_ref().unwrap();
@ -484,38 +516,6 @@ mod unix_signal_handler {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Bye!"); println!("Bye!");
libc::_exit(1);
} else {
#[cfg(feature = "std")]
{
println!("Double crash\n");
#[cfg(target_os = "android")]
let si_addr =
{ ((_info._pad[0] as usize) | ((_info._pad[1] as usize) << 32)) as usize };
#[cfg(not(target_os = "android"))]
let si_addr = { _info.si_addr() as usize };
println!(
"We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.",
si_addr
);
}
// let's yolo-cat the maps for debugging, if possible.
#[cfg(all(target_os = "linux", feature = "std"))]
match std::fs::read_to_string("/proc/self/maps") {
Ok(maps) => println!("maps:\n{}", maps),
Err(e) => println!("Couldn't load mappings: {:?}", e),
};
#[cfg(feature = "std")]
{
println!("Type QUIT to restart the child");
let mut line = String::new();
while line.trim() != "QUIT" {
std::io::stdin().read_line(&mut line).unwrap();
}
}
// TODO tell the parent to not restart
libc::_exit(1); libc::_exit(1);
} }
} }

View File

@ -506,12 +506,12 @@ pub fn find_mapping_for_address(address: usize) -> Result<(usize, usize, String,
} }
}); });
if result.0 != 0 { if result.0 == 0 {
Ok(result)
} else {
Err(Error::Unknown( Err(Error::Unknown(
"Couldn't find a mapping for this address".to_string(), "Couldn't find a mapping for this address".to_string(),
)) ))
} else {
Ok(result)
} }
} }

View File

@ -1045,7 +1045,9 @@ impl AsanRuntime {
let mut fault_address = let mut fault_address =
(self.regs[base_reg as usize] as isize + displacement as isize) as usize; (self.regs[base_reg as usize] as isize + displacement as isize) as usize;
if index_reg != 0 { if index_reg == 0 {
index_reg = 0xffff
} else {
if capstone::arch::arm64::Arm64Reg::ARM64_REG_X0 as u16 <= index_reg if capstone::arch::arm64::Arm64Reg::ARM64_REG_X0 as u16 <= index_reg
&& index_reg <= capstone::arch::arm64::Arm64Reg::ARM64_REG_X28 as u16 && index_reg <= capstone::arch::arm64::Arm64Reg::ARM64_REG_X28 as u16
{ {
@ -1070,8 +1072,6 @@ impl AsanRuntime {
index_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16; index_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16;
} }
fault_address += self.regs[index_reg as usize] as usize; fault_address += self.regs[index_reg as usize] as usize;
} else {
index_reg = 0xffff
} }
let backtrace = Backtrace::new(); let backtrace = Backtrace::new();
@ -1783,11 +1783,11 @@ where
match observer.errors() { match observer.errors() {
None => Ok(false), None => Ok(false),
Some(errors) => { Some(errors) => {
if !errors.errors.is_empty() { if errors.errors.is_empty() {
Ok(false)
} else {
self.errors = Some(errors.clone()); self.errors = Some(errors.clone());
Ok(true) Ok(true)
} else {
Ok(false)
} }
} }
} }