rust(lint): use is_null() instead of ptr::null_mut()

Bug: #4594
pull/6552/head
Sam Muhammed 3 years ago committed by Victor Julien
parent 23768c7181
commit 922a453da5

@ -50,7 +50,7 @@ impl TemplateTransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {
@ -287,7 +287,7 @@ pub unsafe extern "C" fn rs_template_probing_parser(
_rdir: *mut u8
) -> AppProto {
// Need at least 2 bytes.
if input_len > 1 && input != std::ptr::null_mut() {
if input_len > 1 && !input.is_null() {
let slice = build_slice!(input, input_len as usize);
if probe(slice).is_ok() {
return ALPROTO_TEMPLATE;
@ -340,7 +340,7 @@ pub unsafe extern "C" fn rs_template_parse_request(
let state = cast_pointer!(state, TemplateState);
if input == std::ptr::null_mut() && input_len > 0 {
if input.is_null() && input_len > 0 {
// Here we have a gap signaled by the input being null, but a greater
// than 0 input_len which provides the size of the gap.
state.on_request_gap(input_len);
@ -368,7 +368,7 @@ pub unsafe extern "C" fn rs_template_parse_response(
};
let state = cast_pointer!(state, TemplateState);
if input == std::ptr::null_mut() && input_len > 0 {
if input.is_null() && input_len > 0 {
// Here we have a gap signaled by the input being null, but a greater
// than 0 input_len which provides the size of the gap.
state.on_response_gap(input_len);

@ -1158,7 +1158,7 @@ pub unsafe extern "C" fn rs_dcerpc_parse_request(
if flags & (core::STREAM_START|core::STREAM_MIDSTREAM) == (core::STREAM_START|core::STREAM_MIDSTREAM) {
state.ts_gap = true;
}
if input_len > 0 && input != std::ptr::null_mut() {
if input_len > 0 && !input.is_null() {
let buf = build_slice!(input, input_len as usize);
state.flow = Some(flow);
return state.handle_input_data(buf, core::STREAM_TOSERVER);
@ -1180,7 +1180,7 @@ pub unsafe extern "C" fn rs_dcerpc_parse_response(
state.tc_gap = true;
}
if input_len > 0 {
if input != std::ptr::null_mut() {
if !input.is_null() {
let buf = build_slice!(input, input_len as usize);
state.flow = Some(flow);
return state.handle_input_data(buf, core::STREAM_TOCLIENT);

@ -210,7 +210,7 @@ pub unsafe extern "C" fn rs_dcerpc_udp_parse(
input: *const u8, input_len: u32, _data: *const std::os::raw::c_void, _flags: u8,
) -> AppLayerResult {
let state = cast_pointer!(state, DCERPCUDPState);
if input_len > 0 && input != std::ptr::null_mut() {
if input_len > 0 && !input.is_null() {
let buf = build_slice!(input, input_len as usize);
return state.handle_input_data(buf);
}

@ -288,7 +288,7 @@ pub unsafe extern "C" fn rs_dcerpc_iface_parse(carg: *const c_char) -> *mut c_vo
#[no_mangle]
pub unsafe extern "C" fn rs_dcerpc_iface_free(ptr: *mut c_void) {
if ptr != std::ptr::null_mut() {
if !ptr.is_null() {
std::mem::drop(Box::from_raw(ptr as *mut DCEIfaceData));
}
}
@ -335,7 +335,7 @@ pub unsafe extern "C" fn rs_dcerpc_opnum_parse(carg: *const c_char) -> *mut c_vo
#[no_mangle]
pub unsafe extern "C" fn rs_dcerpc_opnum_free(ptr: *mut c_void) {
if ptr != std::ptr::null_mut() {
if !ptr.is_null() {
std::mem::drop(Box::from_raw(ptr as *mut DCEOpnumData));
}
}

@ -96,7 +96,7 @@ impl DHCPTransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
sc_app_layer_decoder_events_free_events(&mut self.events);
}
match self.de_state {

@ -115,7 +115,7 @@ pub unsafe extern "C" fn rs_detect_dns_opcode_parse(carg: *const c_char) -> *mut
#[no_mangle]
pub unsafe extern "C" fn rs_dns_detect_opcode_free(ptr: *mut c_void) {
if ptr != std::ptr::null_mut() {
if !ptr.is_null() {
std::mem::drop(Box::from_raw(ptr as *mut DetectDnsOpcode));
}
}

@ -250,7 +250,7 @@ impl DNSTransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
match self.de_state {
@ -719,7 +719,7 @@ pub unsafe extern "C" fn rs_dns_parse_request_tcp(_flow: *const core::Flow,
-> AppLayerResult {
let state = cast_pointer!(state, DNSState);
if input_len > 0 {
if input != std::ptr::null_mut() {
if !input.is_null() {
let buf = std::slice::from_raw_parts(input, input_len as usize);
return state.parse_request_tcp(buf);
}
@ -739,7 +739,7 @@ pub unsafe extern "C" fn rs_dns_parse_response_tcp(_flow: *const core::Flow,
-> AppLayerResult {
let state = cast_pointer!(state, DNSState);
if input_len > 0 {
if input != std::ptr::null_mut() {
if !input.is_null() {
let buf = std::slice::from_raw_parts(input, input_len as usize);
return state.parse_response_tcp(buf);
}

@ -166,13 +166,13 @@ impl HTTP2Transaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {
core::sc_detect_engine_state_free(state);
}
if self.file_range != std::ptr::null_mut() {
if !self.file_range.is_null() {
match unsafe { SC } {
None => panic!("BUG no suricata_config"),
Some(c) => {
@ -224,7 +224,7 @@ impl HTTP2Transaction {
match range::http2_parse_check_content_range(&value) {
Ok((_, v)) => {
range::http2_range_open(self, &v, flow, sfcm, flags, decompressed);
if over && self.file_range != std::ptr::null_mut() {
if over && !self.file_range.is_null() {
range::http2_range_close(self, files, flags, &[])
}
}
@ -234,7 +234,7 @@ impl HTTP2Transaction {
}
}
} else {
if self.file_range != std::ptr::null_mut() {
if !self.file_range.is_null() {
if over {
range::http2_range_close(self, files, flags, decompressed)
} else {
@ -1008,7 +1008,7 @@ export_tx_data_get!(rs_http2_get_tx_data, HTTP2Transaction);
pub unsafe extern "C" fn rs_http2_probing_parser_tc(
_flow: *const Flow, _direction: u8, input: *const u8, input_len: u32, _rdir: *mut u8,
) -> AppProto {
if input != std::ptr::null_mut() {
if !input.is_null() {
let slice = build_slice!(input, input_len as usize);
match parser::http2_parse_frame_header(slice) {
Ok((_, header)) => {
@ -1049,7 +1049,7 @@ pub extern "C" fn rs_http2_state_new(
let state = HTTP2State::new();
let boxed = Box::new(state);
let r = Box::into_raw(boxed) as *mut _;
if orig_state != std::ptr::null_mut() {
if !orig_state.is_null() {
//we could check ALPROTO_HTTP1 == orig_proto
unsafe {
HTTP2MimicHttp1Request(orig_state, r);

@ -129,7 +129,7 @@ impl IKETransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {
@ -316,7 +316,7 @@ pub unsafe extern "C" fn rs_ike_probing_parser(
return ALPROTO_FAILED;
}
if input != std::ptr::null_mut() {
if !input.is_null() {
let slice = build_slice!(input, input_len as usize);
if probe(slice, direction, rdir) {
return ALPROTO_IKE ;

@ -235,7 +235,7 @@ impl KRB5Transaction {
impl Drop for KRB5Transaction {
fn drop(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {

@ -84,7 +84,7 @@ impl MQTTTransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {

@ -217,7 +217,7 @@ impl NFSTransaction {
pub fn free(&mut self) {
debug_validate_bug_on!(self.tx_data.files_opened > 1);
debug_validate_bug_on!(self.tx_data.files_logged > 1);
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
sc_app_layer_decoder_events_free_events(&mut self.events);
}
match self.de_state {

@ -149,7 +149,7 @@ impl NTPTransaction {
}
fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
}

@ -410,7 +410,7 @@ fn probe_rdp(input: &[u8]) -> bool {
pub unsafe extern "C" fn rs_rdp_probe_ts_tc(
_flow: *const Flow, _direction: u8, input: *const u8, input_len: u32, _rdir: *mut u8,
) -> AppProto {
if input != std::ptr::null_mut() {
if !input.is_null() {
// probe bytes for `rdp` protocol pattern
let slice = build_slice!(input, input_len as usize);

@ -75,7 +75,7 @@ impl RFBTransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {

@ -149,7 +149,7 @@ impl SIPTransaction {
impl Drop for SIPTransaction {
fn drop(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {

@ -568,7 +568,7 @@ impl SMBTransaction {
pub fn free(&mut self) {
debug_validate_bug_on!(self.tx_data.files_opened > 1);
debug_validate_bug_on!(self.tx_data.files_logged > 1);
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
sc_app_layer_decoder_events_free_events(&mut self.events);
}
match self.de_state {

@ -267,7 +267,7 @@ impl<'a> SNMPTransaction<'a> {
}
fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
}

@ -99,7 +99,7 @@ impl SSHTransaction {
}
pub fn free(&mut self) {
if self.events != std::ptr::null_mut() {
if !self.events.is_null() {
core::sc_app_layer_decoder_events_free_events(&mut self.events);
}
if let Some(state) = self.de_state {

Loading…
Cancel
Save