]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/probing: safety check for null input
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 7 May 2024 14:33:00 +0000 (16:33 +0200)
committerPhilippe Antoine <pantoine@oisf.net>
Thu, 23 May 2024 20:14:00 +0000 (22:14 +0200)
Ticket: 7013

Done consistently for all protocols

This may change some protocols behaviors which failed early
if they found there was not enough data...

(cherry picked from commit 37a9003736413b0bc9704099e189fd402922df43)

rust/src/dcerpc/dcerpc.rs
rust/src/dcerpc/dcerpc_udp.rs
rust/src/dhcp/dhcp.rs
rust/src/dns/dns.rs
rust/src/krb/krb5.rs
rust/src/mqtt/mqtt.rs
rust/src/nfs/nfs.rs
rust/src/ntp/ntp.rs
rust/src/smb/smb.rs
rust/src/snmp/snmp.rs

index f2a6a46eaf85b1eade8e6050807a50dd2636a534..ec2bc86cbdd046f7062b74b4db09b0f917a4ef90 100644 (file)
@@ -1351,7 +1351,7 @@ pub extern "C" fn rs_dcerpc_probe_tcp(direction: u8, input: *const u8,
                                       len: u32, rdir: *mut u8) -> i32
 {
     SCLogDebug!("Probing packet for DCERPC");
-    if len == 0 {
+    if len == 0 || input.is_null() {
         return core::ALPROTO_UNKNOWN;
     }
     let slice: &[u8] = unsafe {
index e39c5f14a091bcf2f173ab1a38fe4d1f2935d747..224f3e1aa6eb7867ad409a332119f570dcbe38ca 100644 (file)
@@ -325,7 +325,7 @@ pub extern "C" fn rs_dcerpc_probe_udp(direction: u8, input: *const u8,
                                       len: u32, rdir: *mut u8) -> i32
 {
     SCLogDebug!("Probing the packet for DCERPC/UDP");
-    if len == 0 {
+    if len == 0 || input.is_null() {
         return core::ALPROTO_UNKNOWN;
     }
     let slice: &[u8] = unsafe {
index 540c79976f915312c5b8769f204683b2610e4345..1dcd49104ef6e931757704ddde413950a2091310 100644 (file)
@@ -231,7 +231,7 @@ pub extern "C" fn rs_dhcp_probing_parser(_flow: *const Flow,
                                          input_len: u32,
                                          _rdir: *mut u8) -> AppProto
 {
-    if input_len < DHCP_MIN_FRAME_LEN {
+    if input_len < DHCP_MIN_FRAME_LEN || input.is_null() {
         return ALPROTO_UNKNOWN;
     }
 
index 6307fa091abd04c97315141071e8ca69064ad7f5..51d921d0ff073528dda0df840240074cdc45fc3f 100644 (file)
@@ -1063,7 +1063,7 @@ pub extern "C" fn rs_dns_probe(
     len: u32,
     rdir: *mut u8,
 ) -> AppProto {
-    if len == 0 || len < std::mem::size_of::<DNSHeader>() as u32 {
+    if input.is_null() || len < std::mem::size_of::<DNSHeader>() as u32 {
         return core::ALPROTO_UNKNOWN;
     }
     let slice: &[u8] = unsafe {
@@ -1092,7 +1092,7 @@ pub extern "C" fn rs_dns_probe_tcp(
     len: u32,
     rdir: *mut u8
 ) -> AppProto {
-    if len == 0 || len < std::mem::size_of::<DNSHeader>() as u32 + 2 {
+    if input.is_null() || len < std::mem::size_of::<DNSHeader>() as u32 + 2 {
         return core::ALPROTO_UNKNOWN;
     }
     let slice: &[u8] = unsafe {
index e81e3e8c935a2a3b34fac9c35d0829ab9935198d..d1f566caa7c5028df3cb2b3ce92a3a0b97aeb24b 100644 (file)
@@ -417,6 +417,9 @@ pub extern "C" fn rs_krb5_probing_parser(_flow: *const Flow,
         input:*const u8, input_len: u32,
         _rdir: *mut u8) -> AppProto
 {
+    if input.is_null() {
+        return ALPROTO_UNKNOWN;
+    }
     let slice = build_slice!(input,input_len as usize);
     let alproto = unsafe{ ALPROTO_KRB5 };
     if slice.len() <= 10 { return unsafe{ALPROTO_FAILED}; }
@@ -455,6 +458,9 @@ pub extern "C" fn rs_krb5_probing_parser_tcp(_flow: *const Flow,
         input:*const u8, input_len: u32,
         rdir: *mut u8) -> AppProto
 {
+    if input.is_null() {
+        return ALPROTO_UNKNOWN;
+    }
     let slice = build_slice!(input,input_len as usize);
     if slice.len() <= 14 { return unsafe{ALPROTO_FAILED}; }
     match be_u32(slice) as IResult<&[u8],u32> {
index 5f210be8b90d95be1f7571c05533ea600500b759..7829574f1b3fce0683fe8b75536f976b83500b4d 100644 (file)
@@ -604,6 +604,9 @@ pub extern "C" fn rs_mqtt_probing_parser(
     input_len: u32,
     _rdir: *mut u8,
 ) -> AppProto {
+    if input.is_null() {
+        return ALPROTO_UNKNOWN;
+    }
     let buf = build_slice!(input, input_len as usize);
     match parse_fixed_header(buf) {
         Ok((_, hdr)) => {
index 581b9dc2c419545cdaf7340b29100a5fb07d6f68..7bdf620121443a0319aaf3658af395e8c54550d9 100644 (file)
@@ -1873,6 +1873,9 @@ pub extern "C" fn rs_nfs_probe_ms(
         direction: u8, input: *const u8,
         len: u32, rdir: *mut u8) -> i8
 {
+    if input.is_null() {
+        return 0;
+    }
     let slice: &[u8] = build_slice!(input, len as usize);
     SCLogDebug!("rs_nfs_probe_ms: probing direction {:02x}", direction);
     let mut adirection : u8 = 0;
@@ -1907,6 +1910,9 @@ pub extern "C" fn rs_nfs_probe(direction: u8,
         input: *const u8, len: u32)
     -> i8
 {
+    if input.is_null() {
+        return 0;
+    }
     let slice: &[u8] = build_slice!(input, len as usize);
     SCLogDebug!("rs_nfs_probe: running probe");
     return nfs_probe(slice, direction);
@@ -1917,6 +1923,9 @@ pub extern "C" fn rs_nfs_probe(direction: u8,
 pub extern "C" fn rs_nfs_probe_udp_ts(input: *const u8, len: u32)
                                -> i8
 {
+    if input.is_null() {
+        return 0;
+    }
     let slice: &[u8] = build_slice!(input, len as usize);
     return nfs_probe_udp(slice, STREAM_TOSERVER);
 }
@@ -1926,6 +1935,9 @@ pub extern "C" fn rs_nfs_probe_udp_ts(input: *const u8, len: u32)
 pub extern "C" fn rs_nfs_probe_udp_tc(input: *const u8, len: u32)
                                -> i8
 {
+    if input.is_null() {
+        return 0;
+    }
     let slice: &[u8] = build_slice!(input, len as usize);
     return nfs_probe_udp(slice, STREAM_TOCLIENT);
 }
index eeda47f77453803fb1a1f5018570a852920c6cd1..97ab9d56022d801bbc25adff51ae95aa291990b1 100644 (file)
@@ -361,6 +361,9 @@ pub extern "C" fn ntp_probing_parser(_flow: *const Flow,
         input:*const u8, input_len: u32,
         _rdir: *mut u8) -> AppProto
 {
+    if input.is_null() {
+        return ALPROTO_UNKNOWN;
+    }
     let slice: &[u8] = unsafe { std::slice::from_raw_parts(input as *mut u8, input_len as usize) };
     let alproto = unsafe{ ALPROTO_NTP };
     match parse_ntp(slice) {
index 0096c3384aeb6cb3868a787bfbbd97461b21c916..15be61f933a0c07c0d74ee74662192684ca48cbc 100644 (file)
@@ -2055,7 +2055,7 @@ fn smb_probe_tcp(direction: u8, slice: &[u8], rdir: *mut u8, begins: bool) -> i8
 pub extern "C" fn rs_smb_probe_begins_tcp(direction: u8, input: *const u8, len: u32, rdir: *mut u8)
     -> i8
 {
-    if len < MIN_REC_SIZE as u32 {
+    if len < MIN_REC_SIZE as u32 || input.is_null() {
         return 0;
     }
     let slice = build_slice!(input, len as usize);
@@ -2068,7 +2068,7 @@ pub extern "C" fn rs_smb_probe_begins_tcp(direction: u8, input: *const u8, len:
 pub extern "C" fn rs_smb_probe_tcp(direction: u8, input: *const u8, len: u32, rdir: *mut u8)
     -> i8
 {
-    if len < MIN_REC_SIZE as u32 {
+    if len < MIN_REC_SIZE as u32 || input.is_null() {
         return 0;
     }
     let slice = build_slice!(input, len as usize);
index ad461311c84277917d132badbd39bbeeb9b13b07..7fef09d9aff148f1e6f15d0464adea0035483e87 100644 (file)
@@ -544,6 +544,9 @@ pub extern "C" fn rs_snmp_probing_parser(_flow: *const Flow,
                                          input:*const u8,
                                          input_len: u32,
                                          _rdir: *mut u8) -> AppProto {
+    if input.is_null() {
+        return ALPROTO_UNKNOWN;
+    }
     let slice = build_slice!(input,input_len as usize);
     let alproto = unsafe{ ALPROTO_SNMP };
     if slice.len() < 4 { return unsafe{ALPROTO_FAILED}; }