]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: fix clippy lints for clippy::bool_comparison
authorJason Ish <jason.ish@oisf.net>
Wed, 5 Oct 2022 14:59:48 +0000 (08:59 -0600)
committerVictor Julien <vjulien@oisf.net>
Mon, 24 Oct 2022 09:20:08 +0000 (11:20 +0200)
rust/src/applayer.rs
rust/src/dcerpc/dcerpc.rs
rust/src/dcerpc/log.rs
rust/src/filetracker.rs
rust/src/nfs/nfs.rs
rust/src/smb/dcerpc.rs
rust/src/smb/smb2.rs

index edb5891e2afd06f16cf519daacbb3ca1f3eccbaf..a9b2135bb4eea570d6c63b40c38bf1c1bfe04d27 100644 (file)
@@ -268,7 +268,7 @@ impl AppLayerResult {
 
 impl From<bool> for AppLayerResult {
     fn from(v: bool) -> Self {
-        if v == false {
+        if !v {
             Self::err()
         } else {
             Self::ok()
index b180ccaaa339d06184e89d23ecfdfcb8a94c4c67..eed4408b5776d7c1d21ee898a842388a909bfa36 100644 (file)
@@ -565,7 +565,7 @@ impl DCERPCState {
                     SCLogDebug!("post_gap_housekeeping: done");
                     break;
                 }
-                if tx.req_done == false {
+                if !tx.req_done {
                     tx.req_lost = true;
                 }
                 tx.req_done = true;
@@ -579,10 +579,10 @@ impl DCERPCState {
                     SCLogDebug!("post_gap_housekeeping: done");
                     break;
                 }
-                if tx.req_done == false {
+                if !tx.req_done {
                     tx.req_lost = true;
                 }
-                if tx.resp_done == false {
+                if !tx.resp_done {
                     tx.resp_lost = true;
                 }
                 tx.req_done = true;
@@ -1080,7 +1080,7 @@ impl DCERPCState {
         self.bytes_consumed += retval;
 
         // 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.reset_direction(direction);
         }
index c4e23d980d61e1c3f625ef1ad686dac68781bc2f..6575778326005748c5af6a613d070bdff6d4f24e 100644 (file)
@@ -23,7 +23,7 @@ use crate::jsonbuilder::{JsonBuilder, JsonError};
 fn log_dcerpc_header_tcp(
     jsb: &mut JsonBuilder, state: &DCERPCState, tx: &DCERPCTransaction,
 ) -> 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))?;
         match tx.req_cmd {
             DCERPC_TYPE_REQUEST => {
@@ -56,7 +56,7 @@ fn log_dcerpc_header_tcp(
         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))?;
         match tx.resp_cmd {
             DCERPC_TYPE_RESPONSE => {
@@ -83,7 +83,7 @@ fn log_dcerpc_header_tcp(
 fn log_dcerpc_header_udp(
     jsb: &mut JsonBuilder, _state: &DCERPCUDPState, tx: &DCERPCTransaction,
 ) -> 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))?;
         match tx.req_cmd {
             DCERPC_TYPE_REQUEST => {
@@ -99,7 +99,7 @@ fn log_dcerpc_header_udp(
         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))?;
         match tx.resp_cmd {
             DCERPC_TYPE_RESPONSE => {
index dda6ea8084eff476affae8bf866a4b7724f6fbe9..0d4fc394d51ba3db575fd127fcd5e7bbadc7d9d1 100644 (file)
@@ -79,7 +79,7 @@ impl FileTransferTracker {
     }
 
     pub fn is_done(&self) -> bool {
-        self.file_open == false
+        !self.file_open
     }
 
     fn open(&mut self, config: &'static SuricataFileContext,
@@ -112,7 +112,7 @@ impl FileTransferTracker {
     }
 
     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);
     }
@@ -146,13 +146,13 @@ impl FileTransferTracker {
         self.fill_bytes = fill_bytes;
         self.chunk_is_last = is_last;
 
-        if self.file_open == false {
+        if !self.file_open {
             SCLogDebug!("NEW CHUNK: FILE OPEN");
             self.track_id = *xid;
             self.open(config, files, flags, name);
         }
 
-        if self.file_open == true {
+        if self.file_open {
             let res = self.update(files, flags, data, 0);
             SCLogDebug!("NEW CHUNK: update res {:?}", res);
             return res;
@@ -173,7 +173,7 @@ impl FileTransferTracker {
 
         if self.chunk_left == 0 && self.fill_bytes == 0 {
             //SCLogDebug!("UPDATE: nothing to do");
-            if self.chunk_is_last == true {
+            if self.chunk_is_last {
                 SCLogDebug!("last empty chunk, closing");
                 self.close(files, flags);
                 self.chunk_is_last = false;
@@ -199,7 +199,7 @@ impl FileTransferTracker {
             if self.chunk_left <= data.len() as u32 {
                 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);
                     match res {
                         0   => { },
@@ -246,7 +246,7 @@ impl FileTransferTracker {
                 } else {
                     self.chunk_left = 0;
 
-                    if self.chunk_is_ooo == false {
+                    if !self.chunk_is_ooo {
                         loop {
                             let _offset = self.tracked;
                             match self.chunks.remove(&self.tracked) {
@@ -283,7 +283,7 @@ impl FileTransferTracker {
                         self.cur_ooo_chunk_offset = 0;
                     }
                 }
-                if self.chunk_is_last == true {
+                if self.chunk_is_last {
                     SCLogDebug!("last chunk, closing");
                     self.close(files, flags);
                     self.chunk_is_last = false;
@@ -292,7 +292,7 @@ impl FileTransferTracker {
                 }
 
             } else {
-                if self.chunk_is_ooo == false {
+                if !self.chunk_is_ooo {
                     let res = files.file_append(&self.track_id, data, is_gap);
                     match res {
                         0   => { },
index bbbcbe3d63240367b44777066eb67e09a7de3018..e0c2c0cad69e007101235d5f3a5e12f95d1d0292 100644 (file)
@@ -1984,7 +1984,7 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
         ALPROTO_NFS = alproto;
 
         let midstream = conf_get_bool("stream.midstream");
-        if midstream == true {
+        if midstream {
             if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_TCP as u8,
                     parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN,
                     rs_nfs_probe_ms, rs_nfs_probe_ms) == 0 {
index 26de2f9402fd59947ced4aaf3da7233dd9b41aa7..1741e6a0e32ba635a43a5f5c313b01777da16ca9 100644 (file)
@@ -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
              * 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");
                 match parse_dcerpc_request_record(dcer.data, dcer.frag_len, dcer.little_endian) {
                     Ok((_, recr)) => {
@@ -258,7 +258,7 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState,
                     }
                 },
                 DCERPC_TYPE_BIND => {
-                    let brec = if dcer.little_endian == true {
+                    let brec = if dcer.little_endian {
                         parse_dcerpc_bind_record(dcer.data)
                     } else {
                         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() {
                                 let mut ifaces: Vec<DCERPCIface> = Vec::new();
                                 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],
                                              i.iface[5],  i.iface[4],  i.iface[7],  i.iface[6],
                                              i.iface[8],  i.iface[9],  i.iface[10], i.iface[11],
index 77e4f35fe090edf4fa32666f80af3e3eda9d9f9d..96f169ccbd126fca15851c269f4c95ceab268f7c 100644 (file)
@@ -199,7 +199,7 @@ pub fn smb2_read_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>)
                 if share_name.is_empty() && !is_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");
                         // insert fake tree to assist in follow up lookups
                         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 {
                     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");
 
                         let tree = SMBTree::new(b"suricata::dcerpc".to_vec(), true);