]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/ftp: handle NULL inputs
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 10 Sep 2024 09:20:29 +0000 (11:20 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 10 Dec 2024 13:40:04 +0000 (14:40 +0100)
Completes Ticket 7013

rust/src/ftp/mod.rs

index aae5ff4afe56f03d11c916f3aedfeb4396449239..a206aa2f350ceae988cdd6d5dc302104eab06541 100644 (file)
@@ -88,6 +88,9 @@ pub fn ftp_pasv_response(i: &[u8]) -> IResult<&[u8], u16> {
 
 #[no_mangle]
 pub unsafe extern "C" fn rs_ftp_active_port(input: *const u8, len: u32) -> u16 {
+    if input.is_null() {
+        return 0;
+    }
     let buf = build_slice!(input, len as usize);
     match ftp_active_port(buf) {
         Ok((_, dport)) => {
@@ -105,7 +108,10 @@ pub unsafe extern "C" fn rs_ftp_active_port(input: *const u8, len: u32) -> u16 {
 
 #[no_mangle]
 pub unsafe extern "C" fn rs_ftp_pasv_response(input: *const u8, len: u32) -> u16 {
-    let buf = std::slice::from_raw_parts(input, len as usize);
+    if input.is_null() {
+        return 0;
+    }
+    let buf =  build_slice!(input, len as usize);
     match ftp_pasv_response(buf) {
         Ok((_, dport)) => {
             return dport;
@@ -147,6 +153,9 @@ pub fn ftp_active_eprt(i: &[u8]) -> IResult<&[u8], u16> {
 
 #[no_mangle]
 pub unsafe extern "C" fn rs_ftp_active_eprt(input: *const u8, len: u32) -> u16 {
+    if input.is_null() {
+        return 0;
+    }
     let buf = build_slice!(input, len as usize);
     match ftp_active_eprt(buf) {
         Ok((_, dport)) => {
@@ -163,7 +172,10 @@ pub unsafe extern "C" fn rs_ftp_active_eprt(input: *const u8, len: u32) -> u16 {
 }
 #[no_mangle]
 pub unsafe extern "C" fn rs_ftp_epsv_response(input: *const u8, len: u32) -> u16 {
-    let buf = std::slice::from_raw_parts(input, len as usize);
+    if input.is_null() {
+        return 0;
+    }
+    let buf = build_slice!(input, len as usize);
     match ftp_epsv_response(buf) {
         Ok((_, dport)) => {
             return dport;