]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/frames: cleanup clippy lint for unsafe
authorJason Ish <jason.ish@oisf.net>
Mon, 3 Oct 2022 22:15:12 +0000 (16:15 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 4 Oct 2022 09:22:02 +0000 (11:22 +0200)
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.

rust/src/applayer.rs
rust/src/frames.rs

index 3c493a44dab6e76bf9ca79618b30538005e5aeea..523c62a68f4abeee495f85c334577102e2791a80 100644 (file)
@@ -662,18 +662,16 @@ pub trait AppLayerFrameType {
     fn to_cstring(&self) -> *const std::os::raw::c_char;
 
     /// 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() {
             return -1;
         }
-        unsafe {
-            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)
-            } else {
-                -1
-            };
-            frame_id
-        }
+        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)
+        } else {
+            -1
+        };
+        frame_id
     }
 
     /// Converts a variant ID to an FFI safe name.
index 3f1953d5d2fef5f933a432f6ac962691cacd8a10..aa6bf4375ff47b01a133554f80236de85ea86e42 100644 (file)
@@ -49,6 +49,7 @@ impl std::fmt::Debug for Frame {
 }
 
 impl Frame {
+    #[allow(clippy::not_unsafe_ptr_arg_deref)]
     pub fn new(
         flow: *const Flow, stream_slice: &StreamSlice, frame_start: &[u8], frame_len: i64,
         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) {
         unsafe {
             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) {
         unsafe {
             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) {
         unsafe {
             AppLayerFrameAddEventById(flow, self.direction(), self.id, event);