]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: return empty slice without using from_raw_parts
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 7 May 2024 08:18:14 +0000 (10:18 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 15 May 2024 15:03:50 +0000 (17:03 +0200)
As this triggers rustc 1.78
unsafe precondition(s) violated: slice::from_raw_parts requires
the pointer to be aligned and non-null,
and the total size of the slice not to exceed `isize::MAX`

Ticket: 7013

rust/src/applayer.rs

index 522143fb6d0e2bcad097aeb2dd144615dbf4759c..dbf4b2cd2d4c0c6786f62f11ed72d2d8c317c094 100644 (file)
@@ -58,6 +58,9 @@ impl StreamSlice {
         self.input_len
     }
     pub fn as_slice(&self) -> &[u8] {
+        if self.input.is_null() && self.input_len == 0 {
+            return &[];
+        }
         unsafe { std::slice::from_raw_parts(self.input, self.input_len as usize) }
     }
     pub fn is_empty(&self) -> bool {