From db36f39632092510bea85613e65bf9750242e899 Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Sat, 10 Oct 2026 08:47:06 -0400 Subject: [PATCH] ftp: drop null checks from the response line free SCFTPFreeResponseLine gated the release of the code buffer on a null test of the response pointer, so the code buffer had no check of its own. Neither check could fire: parse_response_line sets both pointers from Box::into_raw on a boxed slice, which never returns null, and C code obtains an FTPResponseLine only from SCFTPParseResponseLine. The comment on the code field claimed the pointer may be null; a line with no status code gets an empty buffer with code_length 0 instead. Remove both null checks, note why they are unnecessary, and correct the field comment. Ticket: 8803 --- rust/src/ftp/response.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/rust/src/ftp/response.rs b/rust/src/ftp/response.rs index 004dc1a860..0e322503ea 100644 --- a/rust/src/ftp/response.rs +++ b/rust/src/ftp/response.rs @@ -21,7 +21,7 @@ use std::slice; #[repr(C)] pub struct FTPResponseLine { - code: *mut u8, // Response code as a string (may be null) + code: *mut u8, // Response code as a string; empty if no code response: *mut u8, // Response string length: usize, // Length of the response string code_length: usize, // Length of the response code string @@ -103,19 +103,16 @@ pub unsafe extern "C" fn SCFTPFreeResponseLine(response: *mut FTPResponseLine) { let response = Box::from_raw(response); - if !response.response.is_null() { - let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut( - response.code, - response.code_length, - )); - } - - if !response.response.is_null() { - let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut( - response.response, - response.length, - )); - } + // parse_response_line always sets both buffers from Box::into_raw, so + // neither is null. + let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut( + response.code, + response.code_length, + )); + let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut( + response.response, + response.length, + )); } #[cfg(test)]