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
pull/16459/head
Jeff Lucovsky 2 weeks ago committed by Victor Julien
parent 2054e9bfcf
commit db36f39632

@ -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)]

Loading…
Cancel
Save