From: Philippe Antoine Date: Thu, 6 May 2021 11:30:49 +0000 (+0200) Subject: rust: SCLogDebug is real nop when built as release X-Git-Tag: suricata-6.0.3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d70bbb24f44b9b32fb189b4a3c1e0edb26421b9a;p=thirdparty%2Fsuricata.git rust: SCLogDebug is real nop when built as release Before, even if there were no outputs, all the arguments were evaluated, which could turn expensive All variables which are used only in certain build configurations are now prefixed by underscore to avoid warnings (cherry picked from commit ef5755338fa6404b60e7f90bfbaca039b2bfda1e) --- diff --git a/rust/src/dcerpc/parser.rs b/rust/src/dcerpc/parser.rs index e3f40ff3d9..9771a28be0 100644 --- a/rust/src/dcerpc/parser.rs +++ b/rust/src/dcerpc/parser.rs @@ -102,22 +102,22 @@ named!(pub parse_dcerpc_udp_header, serial_hi: serial_hi, objectuuid: match parse_uuid(objectuuid) { Ok((_, vect)) => assemble_uuid(vect), - Err(e) => { - SCLogDebug!("{}", e); + Err(_e) => { + SCLogDebug!("{}", _e); vec![0] }, }, interfaceuuid: match parse_uuid(interfaceuuid) { Ok((_, vect)) => assemble_uuid(vect), - Err(e) => { - SCLogDebug!("{}", e); + Err(_e) => { + SCLogDebug!("{}", _e); vec![0] }, }, activityuuid: match parse_uuid(activityuuid){ Ok((_, vect)) => assemble_uuid(vect), - Err(e) => { - SCLogDebug!("{}", e); + Err(_e) => { + SCLogDebug!("{}", _e); vec![0] }, }, diff --git a/rust/src/filetracker.rs b/rust/src/filetracker.rs index 667f8c4931..ba159e8d30 100644 --- a/rust/src/filetracker.rs +++ b/rust/src/filetracker.rs @@ -121,10 +121,10 @@ impl FileTransferTracker { self.file_is_truncated = true; } - 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"); } - SCLogDebug!("CREATE: name {:?} file_size {}", name, file_size); + SCLogDebug!("CREATE: name {:?} file_size {}", _name, _file_size); } pub fn new_chunk(&mut self, config: &'static SuricataFileContext, @@ -255,7 +255,7 @@ impl FileTransferTracker { if self.chunk_is_ooo == false { loop { - let offset = self.tracked; + let _offset = self.tracked; match self.chunks.remove(&self.tracked) { Some(c) => { let res = files.file_append(&self.track_id, &c.chunk, c.contains_gap); @@ -273,10 +273,10 @@ impl FileTransferTracker { self.tracked += c.chunk.len() as u64; self.cur_ooo -= c.chunk.len() as u64; - SCLogDebug!("STORED OOO CHUNK at offset {}, tracked now {}, stored len {}", offset, self.tracked, c.chunk.len()); + SCLogDebug!("STORED OOO CHUNK at offset {}, tracked now {}, stored len {}", _offset, self.tracked, c.chunk.len()); }, _ => { - SCLogDebug!("NO STORED CHUNK found at offset {}", self.tracked); + SCLogDebug!("NO STORED CHUNK found at _offset {}", self.tracked); break; }, }; diff --git a/rust/src/ftp/mod.rs b/rust/src/ftp/mod.rs index 81ccab73bd..53c3df7d76 100644 --- a/rust/src/ftp/mod.rs +++ b/rust/src/ftp/mod.rs @@ -101,11 +101,9 @@ pub extern "C" fn rs_ftp_pasv_response(input: *const u8, len: u32) -> u16 { return dport; }, Err(nom::Err::Incomplete(_)) => { - let buf = unsafe{std::slice::from_raw_parts(input, len as usize)}; SCLogDebug!("pasv incomplete: '{:?}'", String::from_utf8_lossy(buf)); }, Err(_) => { - let buf = unsafe{std::slice::from_raw_parts(input, len as usize)}; SCLogDebug!("pasv error on '{:?}'", String::from_utf8_lossy(buf)); }, } @@ -166,11 +164,9 @@ pub extern "C" fn rs_ftp_epsv_response(input: *const u8, len: u32) -> u16 { return dport; }, Err(nom::Err::Incomplete(_)) => { - let buf = unsafe{std::slice::from_raw_parts(input, len as usize)}; SCLogDebug!("epsv incomplete: '{:?}'", String::from_utf8_lossy(buf)); }, Err(_) => { - let buf = unsafe{std::slice::from_raw_parts(input, len as usize)}; SCLogDebug!("epsv incomplete: '{:?}'", String::from_utf8_lossy(buf)); }, diff --git a/rust/src/log.rs b/rust/src/log.rs index 3dcd91ef01..b61c6cddaf 100644 --- a/rust/src/log.rs +++ b/rust/src/log.rs @@ -167,8 +167,7 @@ macro_rules!SCLogDebug { #[cfg(not(feature = "debug"))] #[macro_export] macro_rules!SCLogDebug { - ($last:expr) => { let _ = &$last; let _ = $crate::log::Level::Debug; }; - ($one:expr, $($arg:tt)*) => { let _ = &$one; SCLogDebug!($($arg)*); }; + ($($arg:tt)*) => () } /// SCLogMessage wrapper. If the Suricata C context is not registered diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index 7667c65d6d..112abbd944 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -1056,9 +1056,9 @@ impl NFSState { if self.ts_gap { SCLogDebug!("TS trying to catch up after GAP (input {})", cur_i.len()); - let mut cnt = 0; + let mut _cnt = 0; while cur_i.len() > 0 { - cnt += 1; + _cnt += 1; match nfs_probe(cur_i, STREAM_TOSERVER) { 1 => { SCLogDebug!("expected data found"); @@ -1067,13 +1067,13 @@ impl NFSState { }, 0 => { SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.", - cur_i.len(), cnt); + cur_i.len(), _cnt); return AppLayerResult::incomplete((i.len() - cur_i.len()) as u32, (cur_i.len() + 1) as u32); }, -1 => { cur_i = &cur_i[1..]; if cur_i.len() == 0 { - SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", cnt); + SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", _cnt); } }, _ => { @@ -1209,9 +1209,9 @@ impl NFSState { if self.tc_gap { SCLogDebug!("TC trying to catch up after GAP (input {})", cur_i.len()); - let mut cnt = 0; + let mut _cnt = 0; while cur_i.len() > 0 { - cnt += 1; + _cnt += 1; match nfs_probe(cur_i, STREAM_TOCLIENT) { 1 => { SCLogDebug!("expected data found"); @@ -1220,13 +1220,13 @@ impl NFSState { }, 0 => { SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.", - cur_i.len(), cnt); + cur_i.len(), _cnt); return AppLayerResult::incomplete((i.len() - cur_i.len()) as u32, (cur_i.len() + 1) as u32); }, -1 => { cur_i = &cur_i[1..]; if cur_i.len() == 0 { - SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", cnt); + SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", _cnt); } }, _ => { diff --git a/rust/src/nfs/nfs4.rs b/rust/src/nfs/nfs4.rs index eb6620b3d5..51d78800e3 100644 --- a/rust/src/nfs/nfs4.rs +++ b/rust/src/nfs/nfs4.rs @@ -186,8 +186,8 @@ impl NFSState { self.commit_v4(r, fh); } } - &Nfs4RequestContent::Close(ref rd) => { - SCLogDebug!("CLOSEv4: {:?}", rd); + &Nfs4RequestContent::Close(ref _rd) => { + SCLogDebug!("CLOSEv4: {:?}", _rd); } &Nfs4RequestContent::Create(ref rd) => { SCLogDebug!("CREATEv4: {:?}", rd); @@ -202,11 +202,11 @@ impl NFSState { xidmap.file_name = rd.to_vec(); main_opcode = NFSPROC4_REMOVE; } - &Nfs4RequestContent::SetClientId(ref rd) => { + &Nfs4RequestContent::SetClientId(ref _rd) => { SCLogDebug!("SETCLIENTIDv4: client id {} r_netid {} r_addr {}", - String::from_utf8_lossy(&rd.client_id), - String::from_utf8_lossy(&rd.r_netid), - String::from_utf8_lossy(&rd.r_addr)); + String::from_utf8_lossy(&_rd.client_id), + String::from_utf8_lossy(&_rd.r_netid), + String::from_utf8_lossy(&_rd.r_addr)); } &_ => { }, } @@ -291,13 +291,13 @@ impl NFSState { for c in &cr.commands { SCLogDebug!("c {:?}", c); match c { - &Nfs4ResponseContent::ReadDir(s, ref rd) => { + &Nfs4ResponseContent::ReadDir(_s, ref rd) => { if let &Some(ref rd) = rd { - SCLogDebug!("READDIRv4: status {} eof {}", s, rd.eof); + SCLogDebug!("READDIRv4: status {} eof {}", _s, rd.eof); for d in &rd.listing { - if let &Some(ref d) = d { - SCLogDebug!("READDIRv4: dir {}", String::from_utf8_lossy(&d.name)); + if let &Some(ref _d) = d { + SCLogDebug!("READDIRv4: dir {}", String::from_utf8_lossy(&_d.name)); } } @@ -329,9 +329,9 @@ impl NFSState { self.process_read_record(r, &reply, Some(&xidmap)); } }, - &Nfs4ResponseContent::Open(s, ref rd) => { - if let &Some(ref rd) = rd { - SCLogDebug!("OPENv4: status {} opendata {:?}", s, rd); + &Nfs4ResponseContent::Open(_s, ref rd) => { + if let &Some(ref _rd) = rd { + SCLogDebug!("OPENv4: status {} opendata {:?}", _s, _rd); insert_filename_with_getfh = true; } }, diff --git a/rust/src/smb/dcerpc.rs b/rust/src/smb/dcerpc.rs index d4265834d8..7e997d6d87 100644 --- a/rust/src/smb/dcerpc.rs +++ b/rust/src/smb/dcerpc.rs @@ -288,10 +288,10 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState, i.iface.to_vec() }; let uuid_str = uuid::Uuid::from_slice(&x.clone()); - let uuid_str = uuid_str.map(|uuid_str| uuid_str.to_hyphenated().to_string()).unwrap(); + let _uuid_str = uuid_str.map(|uuid_str| uuid_str.to_hyphenated().to_string()).unwrap(); let d = DCERPCIface::new(x,i.ver,i.ver_min); SCLogDebug!("UUID {} version {}/{} bytes {:?}", - uuid_str, + _uuid_str, i.ver, i.ver_min,i.iface); ifaces.push(d); } diff --git a/rust/src/smb/smb1.rs b/rust/src/smb/smb1.rs index 274a8246ab..fe7c553133 100644 --- a/rust/src/smb/smb1.rs +++ b/rust/src/smb/smb1.rs @@ -234,14 +234,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { true }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -262,14 +262,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { tx.vercmd.set_smb1_cmd(SMB1_COMMAND_TRANS2); true }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -278,14 +278,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { false } }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -317,14 +317,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { true }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -350,14 +350,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { tx.vercmd.set_smb1_cmd(SMB1_COMMAND_TRANS2); true }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -366,14 +366,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { false } }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -382,14 +382,14 @@ pub fn smb1_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) -> u32 { false } }, - Err(nom::Err::Incomplete(n)) => { - SCLogDebug!("TRANS2 INCOMPLETE {:?}", n); + Err(nom::Err::Incomplete(_n)) => { + SCLogDebug!("TRANS2 INCOMPLETE {:?}", _n); events.push(SMBEvent::MalformedData); false }, - Err(nom::Err::Error(e)) | - Err(nom::Err::Failure(e)) => { - SCLogDebug!("TRANS2 ERROR {:?}", e); + Err(nom::Err::Error(_e)) | + Err(nom::Err::Failure(_e)) => { + SCLogDebug!("TRANS2 ERROR {:?}", _e); events.push(SMBEvent::MalformedData); false }, @@ -812,11 +812,11 @@ pub fn smb1_trans_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) let mut frankenfid = pipe.fid.to_vec(); frankenfid.extend_from_slice(&u32_as_bytes(r.ssn_id)); - let (filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) { + let (_filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) { (n, x) => (n, x), }; SCLogDebug!("smb1_trans_request_record: name {} is_dcerpc {}", - filename, is_dcerpc); + _filename, is_dcerpc); pipe_dcerpc = is_dcerpc; } @@ -853,11 +853,11 @@ pub fn smb1_trans_response_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>) let mut frankenfid = fid.to_vec(); frankenfid.extend_from_slice(&u32_as_bytes(r.ssn_id)); - let (filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) { + let (_filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) { (n, x) => (n, x), }; SCLogDebug!("smb1_trans_response_record: name {} is_dcerpc {}", - filename, is_dcerpc); + _filename, is_dcerpc); // if we get status 'BUFFER_OVERFLOW' this is only a part of // the data. Store it in the ssn/tree for later use. diff --git a/rust/src/smb/smb2.rs b/rust/src/smb/smb2.rs index fcf968e823..c25cf0cca6 100644 --- a/rust/src/smb/smb2.rs +++ b/rust/src/smb/smb2.rs @@ -579,20 +579,20 @@ pub fn smb2_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>) if r.nt_status == SMB_NTSTATUS_SUCCESS { match parse_smb2_response_write(r.data) { - Ok((_, wr)) => { - SCLogDebug!("SMBv2: Write response => {:?}", wr); + Ok((_, _wr)) => { + SCLogDebug!("SMBv2: Write response => {:?}", _wr); /* search key-guid map */ let guid_key = SMBCommonHdr::new(SMBHDR_TYPE_GUID, r.session_id, r.tree_id, r.message_id); - let guid_vec = match state.ssn2vec_map.remove(&guid_key) { + let _guid_vec = match state.ssn2vec_map.remove(&guid_key) { Some(p) => p, None => { SCLogDebug!("SMBv2 response: GUID NOT FOUND"); Vec::new() }, }; - SCLogDebug!("SMBv2 write response for GUID {:?}", guid_vec); + SCLogDebug!("SMBv2 write response for GUID {:?}", _guid_vec); } _ => { events.push(SMBEvent::MalformedData); diff --git a/rust/src/smb/smb2_ioctl.rs b/rust/src/smb/smb2_ioctl.rs index 93e5f381d2..835672f752 100644 --- a/rust/src/smb/smb2_ioctl.rs +++ b/rust/src/smb/smb2_ioctl.rs @@ -20,6 +20,7 @@ use crate::smb::smb2::*; use crate::smb::smb2_records::*; use crate::smb::dcerpc::*; use crate::smb::events::*; +#[cfg(feature = "debug")] use crate::smb::funcs::*; #[derive(Debug)] diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index a712d0f3af..7031d8e61a 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -195,8 +195,8 @@ impl<'a> SNMPState<'a> { Ok((_rem,SnmpGenericMessage::V1(msg))) | Ok((_rem,SnmpGenericMessage::V2(msg))) => self.handle_snmp_v12(msg, direction), Ok((_rem,SnmpGenericMessage::V3(msg))) => self.handle_snmp_v3(msg, direction), - Err(e) => { - SCLogDebug!("parse_snmp failed: {:?}", e); + Err(_e) => { + SCLogDebug!("parse_snmp failed: {:?}", _e); self.set_event(SNMPEvent::MalformedData); -1 }, diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index c58c4b47cd..50cf6e30f2 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -256,15 +256,15 @@ impl SSHState { panic!("SSH invalid length record header"); } } - Err(e) => { - SCLogDebug!("SSH invalid record header {}", e); + Err(_e) => { + SCLogDebug!("SSH invalid record header {}", _e); self.set_event(SSHEvent::InvalidRecord); return AppLayerResult::err(); } } } - Err(e) => { - SCLogDebug!("SSH invalid record {}", e); + Err(_e) => { + SCLogDebug!("SSH invalid record {}", _e); self.set_event(SSHEvent::InvalidRecord); return AppLayerResult::err(); } @@ -294,8 +294,8 @@ impl SSHState { Err(nom::Err::Incomplete(_)) => { return AppLayerResult::incomplete(0 as u32, (input.len() + 1) as u32); } - Err(e) => { - SCLogDebug!("SSH invalid banner {}", e); + Err(_e) => { + SCLogDebug!("SSH invalid banner {}", _e); self.set_event(SSHEvent::InvalidBanner); return AppLayerResult::err(); } @@ -353,8 +353,8 @@ impl SSHState { } } } - Err(e) => { - SCLogDebug!("SSH invalid banner {}", e); + Err(_e) => { + SCLogDebug!("SSH invalid banner {}", _e); self.set_event(SSHEvent::InvalidBanner); return AppLayerResult::err(); }