From: Philippe Antoine Date: Tue, 10 Sep 2024 09:20:29 +0000 (+0200) Subject: rust/ftp: handle NULL inputs X-Git-Tag: suricata-8.0.0-beta1~656 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e62c7d733b94ca9380e24bd4c85825c1a2cef3c7;p=thirdparty%2Fsuricata.git rust/ftp: handle NULL inputs Completes Ticket 7013 --- diff --git a/rust/src/ftp/mod.rs b/rust/src/ftp/mod.rs index aae5ff4afe..a206aa2f35 100644 --- a/rust/src/ftp/mod.rs +++ b/rust/src/ftp/mod.rs @@ -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;