]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: fix clippy lints for clippy::unnecessary_cast
authorJason Ish <jason.ish@oisf.net>
Wed, 5 Oct 2022 15:07:07 +0000 (09:07 -0600)
committerVictor Julien <vjulien@oisf.net>
Mon, 24 Oct 2022 09:20:09 +0000 (11:20 +0200)
12 files changed:
rust/src/dcerpc/dcerpc.rs
rust/src/dns/dns.rs
rust/src/filetracker.rs
rust/src/http2/detect.rs
rust/src/http2/http2.rs
rust/src/nfs/nfs3.rs
rust/src/nfs/nfs4_records.rs
rust/src/smb/dcerpc.rs
rust/src/smb/smb.rs
rust/src/smb/smb2_records.rs
rust/src/ssh/ssh.rs
rust/src/telnet/telnet.rs

index 5f1a0cc49e9b772dc95a12d9b3ea01b34c0dfa0c..93ff5116214f032f347090c4db25b9009fd1065e 100644 (file)
@@ -602,7 +602,7 @@ impl DCERPCState {
             }
             d = &d[1..];
         }
-        Err(Err::Incomplete(Needed::new(2 as usize - d.len())))
+        Err(Err::Incomplete(Needed::new(2_usize - d.len())))
     }
 
     /// Makes a call to the nom parser for parsing DCERPC Header.
index 309349f5c3327fc298eb0475b6fb7a03dc4b31d8..0a065b130e551b4f344ac992245443f08ee34c34 100644 (file)
@@ -507,7 +507,7 @@ impl DNSState {
         let mut consumed = 0;
         while !cur_i.is_empty() {
             if cur_i.len() == 1 {
-                return AppLayerResult::incomplete(consumed as u32, 2 as u32);
+                return AppLayerResult::incomplete(consumed as u32, 2_u32);
             }
             let size = match be_u16(cur_i) as IResult<&[u8],u16> {
                 Ok((_, len)) => len,
@@ -556,7 +556,7 @@ impl DNSState {
         let mut consumed = 0;
         while !cur_i.is_empty() {
             if cur_i.len() == 1 {
-                return AppLayerResult::incomplete(consumed as u32, 2 as u32);
+                return AppLayerResult::incomplete(consumed as u32, 2_u32);
             }
             let size = match be_u16(cur_i) as IResult<&[u8],u16> {
                 Ok((_, len)) => len,
index 0d4fc394d51ba3db575fd127fcd5e7bbadc7d9d1..7ddcda832219bf9a2a23858373fbdd78847bcc84 100644 (file)
@@ -165,7 +165,7 @@ impl FileTransferTracker {
     /// If gap_size > 0 'data' should not be used.
     /// return how much we consumed of data
     pub fn update(&mut self, files: &mut FileContainer, flags: u16, data: &[u8], gap_size: u32) -> u32 {
-        let mut consumed = 0 as usize;
+        let mut consumed = 0_usize;
         let is_gap = gap_size > 0;
         if is_gap || gap_size > 0 {
             SCLogDebug!("is_gap {} size {} ooo? {}", is_gap, gap_size, self.chunk_is_ooo);
index 9c233cd4dcf7dd46dfbacd9997477eb68c98ef40..515c9f471edcdc7ca51c34f88637473b9ae8ea26 100644 (file)
@@ -127,7 +127,7 @@ pub unsafe extern "C" fn rs_http2_parse_errorcode(
 fn http2_tx_get_next_priority(
     tx: &mut HTTP2Transaction, direction: Direction, nb: u32,
 ) -> std::os::raw::c_int {
-    let mut pos = 0 as u32;
+    let mut pos = 0_u32;
     if direction == Direction::ToServer {
         for i in 0..tx.frames_ts.len() {
             match &tx.frames_ts[i].data {
@@ -187,7 +187,7 @@ pub unsafe extern "C" fn rs_http2_tx_get_next_priority(
 fn http2_tx_get_next_window(
     tx: &mut HTTP2Transaction, direction: Direction, nb: u32,
 ) -> std::os::raw::c_int {
-    let mut pos = 0 as u32;
+    let mut pos = 0_u32;
     if direction == Direction::ToServer {
         for i in 0..tx.frames_ts.len() {
             match tx.frames_ts[i].data {
@@ -369,7 +369,7 @@ pub unsafe extern "C" fn rs_http2_detect_sizeupdatectx_match(
 pub unsafe extern "C" fn rs_http2_tx_get_header_name(
     tx: &mut HTTP2Transaction, direction: u8, nb: u32, buffer: *mut *const u8, buffer_len: *mut u32,
 ) -> u8 {
-    let mut pos = 0 as u32;
+    let mut pos = 0_u32;
     match direction.into() {
         Direction::ToServer => {
             for i in 0..tx.frames_ts.len() {
@@ -810,7 +810,7 @@ pub unsafe extern "C" fn rs_http2_tx_get_headers_raw(
 pub unsafe extern "C" fn rs_http2_tx_get_header(
     tx: &mut HTTP2Transaction, direction: u8, nb: u32, buffer: *mut *const u8, buffer_len: *mut u32,
 ) -> u8 {
-    let mut pos = 0 as u32;
+    let mut pos = 0_u32;
     match direction.into() {
         Direction::ToServer => {
             for i in 0..tx.frames_ts.len() {
index a8d9fbfb421f010e7bb470c8b2691866dad090c3..404081c94ce21922f0b1adcb929503546052ce19 100644 (file)
@@ -1014,7 +1014,7 @@ impl HTTP2State {
                 self.progress = HTTP2ConnectionState::Http2StateMagicDone;
             } else {
                 //still more buffer
-                return AppLayerResult::incomplete(0 as u32, HTTP2_MAGIC_LEN as u32);
+                return AppLayerResult::incomplete(0_u32, HTTP2_MAGIC_LEN as u32);
             }
         }
         //first consume frame bytes
index 752ed7cde7937b8c63b02017009e03385c20d342..541b6470781d0e898f0e4ff088826e4c588a9448 100644 (file)
@@ -233,7 +233,7 @@ impl NFSState {
 
                 // cut off final eof field
                 let d = if rd.data.len() >= 4 {
-                    &rd.data[..rd.data.len()-4 as usize]
+                    &rd.data[..rd.data.len()-4_usize]
                 } else {
                     rd.data
                 };
index 9bbc91db5200519e08aa08b687e310af3f17ada7..e06fb51d5d98e395e19a66151741904b99e0bcea 100644 (file)
@@ -1646,7 +1646,7 @@ mod tests {
         let (r, attr) = nfs4_parse_attrbits(&buf[4..]).unwrap();
         assert_eq!(r.len(), 0);
         // assert_eq!(attr.attr_mask, 35618163785728);
-        assert_eq!(attr.attr_mask, ((0x00002065 as u64) << 32 | 0 as u64));
+        assert_eq!(attr.attr_mask, (0x00002065_u64 << 32 | 0_u64));
     }
     #[test]
     fn test_nfs4_response_compound() {
index 1741e6a0e32ba635a43a5f5c313b01777da16ca9..25fec7d12aa6396a6bc3081b32907cc1dcb8c48d 100644 (file)
@@ -459,7 +459,7 @@ pub fn smb_read_dcerpc_record<'b>(state: &mut SMBState,
     SCLogDebug!("lets first see if we have prior data");
     // msg_id 0 as this data crosses cmd/reply pairs
     let ehdr = SMBHashKeyHdrGuid::new(SMBCommonHdr::new(SMBHDR_TYPE_TRANS_FRAG,
-            hdr.ssn_id as u64, hdr.tree_id as u32, 0 as u64), guid.to_vec());
+            hdr.ssn_id as u64, hdr.tree_id as u32, 0_u64), guid.to_vec());
     let mut prevdata = match state.ssnguid2vec_map.remove(&ehdr) {
         Some(s) => s,
         None => Vec::new(),
index ddb2bb3a8f517d99997eb30fc1d94c4edd541d70..dfa066d47443428e134ff2b5910f31f8033ba74a 100644 (file)
@@ -1193,7 +1193,7 @@ impl SMBState {
     fn add_nbss_ts_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) -> (Option<Frame>, Option<Frame>, Option<Frame>) {
         let nbss_pdu = Frame::new(flow, stream_slice, input, nbss_len + 4, SMBFrameType::NBSSPdu as u8);
         SCLogDebug!("NBSS PDU frame {:?}", nbss_pdu);
-        let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4 as i64, SMBFrameType::NBSSHdr as u8);
+        let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4_i64, SMBFrameType::NBSSHdr as u8);
         SCLogDebug!("NBSS HDR frame {:?}", nbss_hdr_frame);
         let nbss_data_frame = Frame::new(flow, stream_slice, &input[4..], nbss_len, SMBFrameType::NBSSData as u8);
         SCLogDebug!("NBSS DATA frame {:?}", nbss_data_frame);
@@ -1206,7 +1206,7 @@ impl SMBState {
         smb_pdu
     }
     fn add_smb1_ts_hdr_data_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) {
-        let _smb1_hdr = Frame::new(flow, stream_slice, input, 32 as i64, SMBFrameType::SMB1Hdr as u8);
+        let _smb1_hdr = Frame::new(flow, stream_slice, input, 32_i64, SMBFrameType::SMB1Hdr as u8);
         SCLogDebug!("SMBv1 HDR frame {:?}", _smb1_hdr);
         if input.len() > 32 {
             let _smb1_data = Frame::new(flow, stream_slice, &input[32..], (nbss_len - 32) as i64, SMBFrameType::SMB1Data as u8);
@@ -1234,7 +1234,7 @@ impl SMBState {
         smb_pdu
     }
     fn add_smb3_ts_hdr_data_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) {
-        let _smb3_hdr = Frame::new(flow, stream_slice, input, 52 as i64, SMBFrameType::SMB3Hdr as u8);
+        let _smb3_hdr = Frame::new(flow, stream_slice, input, 52_i64, SMBFrameType::SMB3Hdr as u8);
         SCLogDebug!("SMBv3 HDR frame {:?}", _smb3_hdr);
         if input.len() > 52 {
             let _smb3_data = Frame::new(flow, stream_slice, &input[52..], (nbss_len - 52) as i64, SMBFrameType::SMB3Data as u8);
@@ -1537,7 +1537,7 @@ impl SMBState {
     fn add_nbss_tc_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) -> (Option<Frame>, Option<Frame>, Option<Frame>) {
         let nbss_pdu = Frame::new(flow, stream_slice, input, nbss_len + 4, SMBFrameType::NBSSPdu as u8);
         SCLogDebug!("NBSS PDU frame {:?}", nbss_pdu);
-        let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4 as i64, SMBFrameType::NBSSHdr as u8);
+        let nbss_hdr_frame = Frame::new(flow, stream_slice, input, 4_i64, SMBFrameType::NBSSHdr as u8);
         SCLogDebug!("NBSS HDR frame {:?}", nbss_hdr_frame);
         let nbss_data_frame = Frame::new(flow, stream_slice, &input[4..], nbss_len, SMBFrameType::NBSSData as u8);
         SCLogDebug!("NBSS DATA frame {:?}", nbss_data_frame);
@@ -1578,7 +1578,7 @@ impl SMBState {
         SCLogDebug!("SMBv3 PDU frame {:?}", _smb_pdu);
     }
     fn add_smb3_tc_hdr_data_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nbss_len: i64) {
-        let _smb3_hdr = Frame::new(flow, stream_slice, input, 52 as i64, SMBFrameType::SMB3Hdr as u8);
+        let _smb3_hdr = Frame::new(flow, stream_slice, input, 52_i64, SMBFrameType::SMB3Hdr as u8);
         SCLogDebug!("SMBv3 HDR frame {:?}", _smb3_hdr);
         if input.len() > 52 {
             let _smb3_data = Frame::new(flow, stream_slice, &input[52..], (nbss_len - 52) as i64, SMBFrameType::SMB3Data as u8);
index 4baa61e3359862c49bd07f1de74d627dfd9afe64..a252a32447df6aa71aad241eef56d5b2b0069969 100644 (file)
@@ -599,7 +599,7 @@ pub fn parse_smb2_response_record(i: &[u8]) -> IResult<&[u8], Smb2Record> {
 
 fn smb_basic_search(d: &[u8]) -> usize {
     let needle = b"SMB";
-    let mut r = 0 as usize;
+    let mut r = 0_usize;
     // this could be replaced by aho-corasick
     let iter = d.windows(needle.len());
     for window in iter {
@@ -626,5 +626,5 @@ pub fn search_smb_record<'a>(i: &'a [u8]) -> IResult<&'a [u8], &'a [u8]> {
         }
         d = &d[index + 3..];
     }
-    Err(Err::Incomplete(Needed::new(4 as usize - d.len())))
+    Err(Err::Incomplete(Needed::new(4_usize - d.len())))
 }
index 95564a0a0b4a6643e011e4e84e411e7417f96a85..1f261b1dcddfb8e117e6b9e78e95300f6283c503 100644 (file)
@@ -261,7 +261,7 @@ impl SSHState {
                     return r;
                 }
                 Err(Err::Incomplete(_)) => {
-                    return AppLayerResult::incomplete(0 as u32, (input.len() + 1) as u32);
+                    return AppLayerResult::incomplete(0_u32, (input.len() + 1) as u32);
                 }
                 Err(_e) => {
                     SCLogDebug!("SSH invalid banner {}", _e);
@@ -301,7 +301,7 @@ impl SSHState {
             Err(Err::Incomplete(_)) => {
                 if input.len() < SSH_MAX_BANNER_LEN {
                     //0 consumed, needs at least one more byte
-                    return AppLayerResult::incomplete(0 as u32, (input.len() + 1) as u32);
+                    return AppLayerResult::incomplete(0_u32, (input.len() + 1) as u32);
                 } else {
                     SCLogDebug!(
                         "SSH banner too long {} vs {} and waiting for eol",
index b9102cc682899e09d3e427a0f3fa486ed9bacc52..86e345874618c4f757e0134fcacaca53177158fc 100644 (file)
@@ -176,7 +176,7 @@ impl TelnetState {
                     flow,
                     stream_slice,
                     start,
-                    -1 as i64,
+                    -1_i64,
                     TelnetFrameType::Pdu as u8,
                 );
             }
@@ -187,7 +187,7 @@ impl TelnetState {
                             flow,
                             stream_slice,
                             start,
-                            -1 as i64,
+                            -1_i64,
                             TelnetFrameType::Ctl as u8,
                         )
                     } else {
@@ -195,7 +195,7 @@ impl TelnetState {
                             flow,
                             stream_slice,
                             start,
-                            -1 as i64,
+                            -1_i64,
                             TelnetFrameType::Data as u8,
                         )
                     // app-layer-frame-documentation tag end: parse_request
@@ -280,14 +280,14 @@ impl TelnetState {
         let mut start = input;
         while !start.is_empty() {
             if self.response_frame.is_none() {
-                self.response_frame = Frame::new(flow, stream_slice, start, -1 as i64, TelnetFrameType::Pdu as u8);
+                self.response_frame = Frame::new(flow, stream_slice, start, -1_i64, TelnetFrameType::Pdu as u8);
             }
             if self.response_specific_frame.is_none() {
                 if let Ok((_, is_ctl)) = parser::peek_message_is_ctl(start) {
                     self.response_specific_frame = if is_ctl {
-                        Frame::new(flow, stream_slice, start, -1 as i64, TelnetFrameType::Ctl as u8)
+                        Frame::new(flow, stream_slice, start, -1_i64, TelnetFrameType::Ctl as u8)
                     } else {
-                        Frame::new(flow, stream_slice, start, -1 as i64, TelnetFrameType::Data as u8)
+                        Frame::new(flow, stream_slice, start, -1_i64, TelnetFrameType::Data as u8)
                     };
                 }
             }