rust/frames: cleanup clippy lint for unsafe

Where possible mark the relevant functions unsafe.  Otherwise suppress
the warning for now as this pattern is supposed to be a safe API around
an unsafe one. Might need some further investigation, but in general the
"guarantee" here is provided from the C side.
pull/7966/head
Jason Ish 4 years ago committed by Victor Julien
parent 105d9a5f02
commit 9218da0eb8

@ -662,18 +662,16 @@ pub trait AppLayerFrameType {
fn to_cstring(&self) -> *const std::os::raw::c_char; fn to_cstring(&self) -> *const std::os::raw::c_char;
/// Converts a C string formatted name to a frame type ID. /// Converts a C string formatted name to a frame type ID.
extern "C" fn ffi_id_from_name(name: *const std::os::raw::c_char) -> i32 where Self: Sized { unsafe extern "C" fn ffi_id_from_name(name: *const std::os::raw::c_char) -> i32 where Self: Sized {
if name.is_null() { if name.is_null() {
return -1; return -1;
} }
unsafe { let frame_id = if let Ok(s) = std::ffi::CStr::from_ptr(name).to_str() {
let frame_id = if let Ok(s) = std::ffi::CStr::from_ptr(name).to_str() { Self::from_str(s).map(|t| t.as_u8() as i32).unwrap_or(-1)
Self::from_str(s).map(|t| t.as_u8() as i32).unwrap_or(-1) } else {
} else { -1
-1 };
}; frame_id
frame_id
}
} }
/// Converts a variant ID to an FFI safe name. /// Converts a variant ID to an FFI safe name.

@ -49,6 +49,7 @@ impl std::fmt::Debug for Frame {
} }
impl Frame { impl Frame {
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn new( pub fn new(
flow: *const Flow, stream_slice: &StreamSlice, frame_start: &[u8], frame_len: i64, flow: *const Flow, stream_slice: &StreamSlice, frame_start: &[u8], frame_len: i64,
frame_type: u8, frame_type: u8,
@ -92,18 +93,21 @@ impl Frame {
} }
} }
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_len(&self, flow: *const Flow, len: i64) { pub fn set_len(&self, flow: *const Flow, len: i64) {
unsafe { unsafe {
AppLayerFrameSetLengthById(flow, self.direction(), self.id, len); AppLayerFrameSetLengthById(flow, self.direction(), self.id, len);
}; };
} }
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_tx(&self, flow: *const Flow, tx_id: u64) { pub fn set_tx(&self, flow: *const Flow, tx_id: u64) {
unsafe { unsafe {
AppLayerFrameSetTxIdById(flow, self.direction(), self.id, tx_id); AppLayerFrameSetTxIdById(flow, self.direction(), self.id, tx_id);
}; };
} }
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn add_event(&self, flow: *const Flow, event: u8) { pub fn add_event(&self, flow: *const Flow, event: u8) {
unsafe { unsafe {
AppLayerFrameAddEventById(flow, self.direction(), self.id, event); AppLayerFrameAddEventById(flow, self.direction(), self.id, event);

Loading…
Cancel
Save