rust: fix clippy lints for clippy::bool_comparison

pull/8073/head
Jason Ish 3 years ago committed by Victor Julien
parent e373d9f5e0
commit 6b71d69356

@ -268,7 +268,7 @@ impl AppLayerResult {
impl From<bool> for AppLayerResult { impl From<bool> for AppLayerResult {
fn from(v: bool) -> Self { fn from(v: bool) -> Self {
if v == false { if !v {
Self::err() Self::err()
} else { } else {
Self::ok() Self::ok()

@ -565,7 +565,7 @@ impl DCERPCState {
SCLogDebug!("post_gap_housekeeping: done"); SCLogDebug!("post_gap_housekeeping: done");
break; break;
} }
if tx.req_done == false { if !tx.req_done {
tx.req_lost = true; tx.req_lost = true;
} }
tx.req_done = true; tx.req_done = true;
@ -579,10 +579,10 @@ impl DCERPCState {
SCLogDebug!("post_gap_housekeeping: done"); SCLogDebug!("post_gap_housekeeping: done");
break; break;
} }
if tx.req_done == false { if !tx.req_done {
tx.req_lost = true; tx.req_lost = true;
} }
if tx.resp_done == false { if !tx.resp_done {
tx.resp_lost = true; tx.resp_lost = true;
} }
tx.req_done = true; tx.req_done = true;
@ -1080,7 +1080,7 @@ impl DCERPCState {
self.bytes_consumed += retval; self.bytes_consumed += retval;
// If the query has been completed, clean the buffer and reset the direction // If the query has been completed, clean the buffer and reset the direction
if self.query_completed == true { if self.query_completed {
self.clean_buffer(direction); self.clean_buffer(direction);
self.reset_direction(direction); self.reset_direction(direction);
} }

@ -23,7 +23,7 @@ use crate::jsonbuilder::{JsonBuilder, JsonError};
fn log_dcerpc_header_tcp( fn log_dcerpc_header_tcp(
jsb: &mut JsonBuilder, state: &DCERPCState, tx: &DCERPCTransaction, jsb: &mut JsonBuilder, state: &DCERPCState, tx: &DCERPCTransaction,
) -> Result<(), JsonError> { ) -> Result<(), JsonError> {
if tx.req_done == true && tx.req_lost == false { if tx.req_done && !tx.req_lost {
jsb.set_string("request", &dcerpc_type_string(tx.req_cmd))?; jsb.set_string("request", &dcerpc_type_string(tx.req_cmd))?;
match tx.req_cmd { match tx.req_cmd {
DCERPC_TYPE_REQUEST => { DCERPC_TYPE_REQUEST => {
@ -56,7 +56,7 @@ fn log_dcerpc_header_tcp(
jsb.set_string("request", "REQUEST_LOST")?; jsb.set_string("request", "REQUEST_LOST")?;
} }
if tx.resp_done == true && tx.resp_lost == false { if tx.resp_done && !tx.resp_lost {
jsb.set_string("response", &dcerpc_type_string(tx.resp_cmd))?; jsb.set_string("response", &dcerpc_type_string(tx.resp_cmd))?;
match tx.resp_cmd { match tx.resp_cmd {
DCERPC_TYPE_RESPONSE => { DCERPC_TYPE_RESPONSE => {
@ -83,7 +83,7 @@ fn log_dcerpc_header_tcp(
fn log_dcerpc_header_udp( fn log_dcerpc_header_udp(
jsb: &mut JsonBuilder, _state: &DCERPCUDPState, tx: &DCERPCTransaction, jsb: &mut JsonBuilder, _state: &DCERPCUDPState, tx: &DCERPCTransaction,
) -> Result<(), JsonError> { ) -> Result<(), JsonError> {
if tx.req_done == true && tx.req_lost == false { if tx.req_done && !tx.req_lost {
jsb.set_string("request", &dcerpc_type_string(tx.req_cmd))?; jsb.set_string("request", &dcerpc_type_string(tx.req_cmd))?;
match tx.req_cmd { match tx.req_cmd {
DCERPC_TYPE_REQUEST => { DCERPC_TYPE_REQUEST => {
@ -99,7 +99,7 @@ fn log_dcerpc_header_udp(
jsb.set_string("request", "REQUEST_LOST")?; jsb.set_string("request", "REQUEST_LOST")?;
} }
if tx.resp_done == true && tx.resp_lost == false { if tx.resp_done && !tx.resp_lost {
jsb.set_string("response", &dcerpc_type_string(tx.resp_cmd))?; jsb.set_string("response", &dcerpc_type_string(tx.resp_cmd))?;
match tx.resp_cmd { match tx.resp_cmd {
DCERPC_TYPE_RESPONSE => { DCERPC_TYPE_RESPONSE => {

@ -79,7 +79,7 @@ impl FileTransferTracker {
} }
pub fn is_done(&self) -> bool { pub fn is_done(&self) -> bool {
self.file_open == false !self.file_open
} }
fn open(&mut self, config: &'static SuricataFileContext, fn open(&mut self, config: &'static SuricataFileContext,
@ -112,7 +112,7 @@ impl FileTransferTracker {
} }
pub fn create(&mut self, _name: &[u8], _file_size: u64) { pub fn create(&mut self, _name: &[u8], _file_size: u64) {
if self.file_open == true { panic!("close existing file first"); } if self.file_open { panic!("close existing file first"); }
SCLogDebug!("CREATE: name {:?} file_size {}", _name, _file_size); SCLogDebug!("CREATE: name {:?} file_size {}", _name, _file_size);
} }
@ -146,13 +146,13 @@ impl FileTransferTracker {
self.fill_bytes = fill_bytes; self.fill_bytes = fill_bytes;
self.chunk_is_last = is_last; self.chunk_is_last = is_last;
if self.file_open == false { if !self.file_open {
SCLogDebug!("NEW CHUNK: FILE OPEN"); SCLogDebug!("NEW CHUNK: FILE OPEN");
self.track_id = *xid; self.track_id = *xid;
self.open(config, files, flags, name); self.open(config, files, flags, name);
} }
if self.file_open == true { if self.file_open {
let res = self.update(files, flags, data, 0); let res = self.update(files, flags, data, 0);
SCLogDebug!("NEW CHUNK: update res {:?}", res); SCLogDebug!("NEW CHUNK: update res {:?}", res);
return res; return res;
@ -173,7 +173,7 @@ impl FileTransferTracker {
if self.chunk_left == 0 && self.fill_bytes == 0 { if self.chunk_left == 0 && self.fill_bytes == 0 {
//SCLogDebug!("UPDATE: nothing to do"); //SCLogDebug!("UPDATE: nothing to do");
if self.chunk_is_last == true { if self.chunk_is_last {
SCLogDebug!("last empty chunk, closing"); SCLogDebug!("last empty chunk, closing");
self.close(files, flags); self.close(files, flags);
self.chunk_is_last = false; self.chunk_is_last = false;
@ -199,7 +199,7 @@ impl FileTransferTracker {
if self.chunk_left <= data.len() as u32 { if self.chunk_left <= data.len() as u32 {
let d = &data[0..self.chunk_left as usize]; let d = &data[0..self.chunk_left as usize];
if self.chunk_is_ooo == false { if !self.chunk_is_ooo {
let res = files.file_append(&self.track_id, d, is_gap); let res = files.file_append(&self.track_id, d, is_gap);
match res { match res {
0 => { }, 0 => { },
@ -246,7 +246,7 @@ impl FileTransferTracker {
} else { } else {
self.chunk_left = 0; self.chunk_left = 0;
if self.chunk_is_ooo == false { if !self.chunk_is_ooo {
loop { loop {
let _offset = self.tracked; let _offset = self.tracked;
match self.chunks.remove(&self.tracked) { match self.chunks.remove(&self.tracked) {
@ -283,7 +283,7 @@ impl FileTransferTracker {
self.cur_ooo_chunk_offset = 0; self.cur_ooo_chunk_offset = 0;
} }
} }
if self.chunk_is_last == true { if self.chunk_is_last {
SCLogDebug!("last chunk, closing"); SCLogDebug!("last chunk, closing");
self.close(files, flags); self.close(files, flags);
self.chunk_is_last = false; self.chunk_is_last = false;
@ -292,7 +292,7 @@ impl FileTransferTracker {
} }
} else { } else {
if self.chunk_is_ooo == false { if !self.chunk_is_ooo {
let res = files.file_append(&self.track_id, data, is_gap); let res = files.file_append(&self.track_id, data, is_gap);
match res { match res {
0 => { }, 0 => { },

@ -1984,7 +1984,7 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
ALPROTO_NFS = alproto; ALPROTO_NFS = alproto;
let midstream = conf_get_bool("stream.midstream"); let midstream = conf_get_bool("stream.midstream");
if midstream == true { if midstream {
if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_TCP as u8, if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_TCP as u8,
parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN, parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN,
rs_nfs_probe_ms, rs_nfs_probe_ms) == 0 { rs_nfs_probe_ms, rs_nfs_probe_ms) == 0 {

@ -194,7 +194,7 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState,
/* if this isn't the first frag, simply update the existing /* if this isn't the first frag, simply update the existing
* tx with the additional stub data */ * tx with the additional stub data */
if dcer.packet_type == DCERPC_TYPE_REQUEST && dcer.first_frag == false { if dcer.packet_type == DCERPC_TYPE_REQUEST && !dcer.first_frag {
SCLogDebug!("NOT the first frag. Need to find an existing TX"); SCLogDebug!("NOT the first frag. Need to find an existing TX");
match parse_dcerpc_request_record(dcer.data, dcer.frag_len, dcer.little_endian) { match parse_dcerpc_request_record(dcer.data, dcer.frag_len, dcer.little_endian) {
Ok((_, recr)) => { Ok((_, recr)) => {
@ -258,7 +258,7 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState,
} }
}, },
DCERPC_TYPE_BIND => { DCERPC_TYPE_BIND => {
let brec = if dcer.little_endian == true { let brec = if dcer.little_endian {
parse_dcerpc_bind_record(dcer.data) parse_dcerpc_bind_record(dcer.data)
} else { } else {
parse_dcerpc_bind_record_big(dcer.data) parse_dcerpc_bind_record_big(dcer.data)
@ -271,7 +271,7 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState,
if !bindr.ifaces.is_empty() { if !bindr.ifaces.is_empty() {
let mut ifaces: Vec<DCERPCIface> = Vec::new(); let mut ifaces: Vec<DCERPCIface> = Vec::new();
for i in bindr.ifaces { for i in bindr.ifaces {
let x = if dcer.little_endian == true { let x = if dcer.little_endian {
vec![i.iface[3], i.iface[2], i.iface[1], i.iface[0], vec![i.iface[3], i.iface[2], i.iface[1], i.iface[0],
i.iface[5], i.iface[4], i.iface[7], i.iface[6], i.iface[5], i.iface[4], i.iface[7], i.iface[6],
i.iface[8], i.iface[9], i.iface[10], i.iface[11], i.iface[8], i.iface[9], i.iface[10], i.iface[11],

@ -199,7 +199,7 @@ pub fn smb2_read_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>)
if share_name.is_empty() && !is_pipe { if share_name.is_empty() && !is_pipe {
SCLogDebug!("SMBv2/READ: no tree connect seen, we don't know if we are a pipe"); SCLogDebug!("SMBv2/READ: no tree connect seen, we don't know if we are a pipe");
if smb_dcerpc_probe(rd.data) == true { if smb_dcerpc_probe(rd.data) {
SCLogDebug!("SMBv2/READ: looks like dcerpc"); SCLogDebug!("SMBv2/READ: looks like dcerpc");
// insert fake tree to assist in follow up lookups // insert fake tree to assist in follow up lookups
let tree = SMBTree::new(b"suricata::dcerpc".to_vec(), true); let tree = SMBTree::new(b"suricata::dcerpc".to_vec(), true);
@ -339,7 +339,7 @@ pub fn smb2_write_request_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>)
if share_name.is_empty() && !is_pipe { if share_name.is_empty() && !is_pipe {
SCLogDebug!("SMBv2/WRITE: no tree connect seen, we don't know if we are a pipe"); SCLogDebug!("SMBv2/WRITE: no tree connect seen, we don't know if we are a pipe");
if smb_dcerpc_probe(wr.data) == true { if smb_dcerpc_probe(wr.data) {
SCLogDebug!("SMBv2/WRITE: looks like we have dcerpc"); SCLogDebug!("SMBv2/WRITE: looks like we have dcerpc");
let tree = SMBTree::new(b"suricata::dcerpc".to_vec(), true); let tree = SMBTree::new(b"suricata::dcerpc".to_vec(), true);

Loading…
Cancel
Save