From: Jason Ish Date: Wed, 5 Oct 2022 14:57:27 +0000 (-0600) Subject: rust: fix clippy lints for clippy::len_zero X-Git-Tag: suricata-7.0.0-beta1~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f342d4aacdf27737517f2467c545a3206df67858;p=thirdparty%2Fsuricata.git rust: fix clippy lints for clippy::len_zero --- diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index 3b6a9c2046..a00baaf943 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -127,7 +127,7 @@ impl TemplateState { fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { // We're not interested in empty requests. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -145,7 +145,7 @@ impl TemplateState { } let mut start = input; - while start.len() > 0 { + while !start.is_empty() { match parser::parse_message(start) { Ok((rem, request)) => { start = rem; @@ -175,7 +175,7 @@ impl TemplateState { fn parse_response(&mut self, input: &[u8]) -> AppLayerResult { // We're not interested in empty responses. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -191,7 +191,7 @@ impl TemplateState { self.response_gap = false; } let mut start = input; - while start.len() > 0 { + while !start.is_empty() { match parser::parse_message(start) { Ok((rem, response)) => { start = rem; @@ -396,7 +396,7 @@ pub unsafe extern "C" fn rs_template_get_request_buffer( { let tx = cast_pointer!(tx, TemplateTransaction); if let Some(ref request) = tx.request { - if request.len() > 0 { + if !request.is_empty() { *len = request.len() as u32; *buf = request.as_ptr(); return 1; @@ -415,7 +415,7 @@ pub unsafe extern "C" fn rs_template_get_response_buffer( { let tx = cast_pointer!(tx, TemplateTransaction); if let Some(ref response) = tx.response { - if response.len() > 0 { + if !response.is_empty() { *len = response.len() as u32; *buf = response.as_ptr(); return 1; diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 2d5bca3715..b180ccaaa3 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -437,14 +437,14 @@ impl DCERPCState { } pub fn handle_gap_ts(&mut self) -> u8 { - if self.buffer_ts.len() > 0 { + if !self.buffer_ts.is_empty() { self.buffer_ts.clear(); } return 0; } pub fn handle_gap_tc(&mut self) -> u8 { - if self.buffer_tc.len() > 0 { + if !self.buffer_tc.is_empty() { self.buffer_tc.clear(); } return 0; @@ -976,7 +976,7 @@ impl DCERPCState { } }; - if self.data_needed_for_dir != direction && buffer.len() != 0 { + if self.data_needed_for_dir != direction && !buffer.is_empty() { return AppLayerResult::err(); } diff --git a/rust/src/dhcp/logger.rs b/rust/src/dhcp/logger.rs index 6fe835ebd3..4cd2580949 100644 --- a/rust/src/dhcp/logger.rs +++ b/rust/src/dhcp/logger.rs @@ -44,7 +44,7 @@ impl DHCPLogger { &DHCPOptionWrapper::Generic(ref option) => { match code { DHCP_OPT_TYPE => { - if option.data.len() > 0 { + if !option.data.is_empty() { return Some(option.data[0]); } } @@ -137,7 +137,7 @@ impl DHCPLogger { } } DHCP_OPT_HOSTNAME => { - if option.data.len() > 0 { + if !option.data.is_empty() { js.set_string_from_bytes("hostname", &option.data)?; } @@ -179,7 +179,7 @@ impl DHCPLogger { } fn log_opt_type(&self, js: &mut JsonBuilder, option: &DHCPOptGeneric) -> Result<(), JsonError> { - if option.data.len() > 0 { + if !option.data.is_empty() { let dhcp_type = match option.data[0] { DHCP_TYPE_DISCOVER => "discover", DHCP_TYPE_OFFER => "offer", @@ -210,7 +210,7 @@ impl DHCPLogger { DHCP_PARAM_TFTP_SERVER_IP => "tftp_server_ip", _ => "" }; - if param.len() > 0 { + if !param.is_empty() { js.append_string(param)?; } } diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index e545348d7d..309349f5c3 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -505,7 +505,7 @@ impl DNSState { let mut cur_i = input; let mut consumed = 0; - while cur_i.len() > 0 { + while !cur_i.is_empty() { if cur_i.len() == 1 { return AppLayerResult::incomplete(consumed as u32, 2 as u32); } @@ -554,7 +554,7 @@ impl DNSState { let mut cur_i = input; let mut consumed = 0; - while cur_i.len() > 0 { + while !cur_i.is_empty() { if cur_i.len() == 1 { return AppLayerResult::incomplete(consumed as u32, 2 as u32); } @@ -838,7 +838,7 @@ pub unsafe extern "C" fn rs_dns_tx_get_query_name(tx: &mut DNSTransaction, if let &Some(ref request) = &tx.request { if (i as usize) < request.queries.len() { let query = &request.queries[i as usize]; - if query.name.len() > 0 { + if !query.name.is_empty() { *len = query.name.len() as u32; *buf = query.name.as_ptr(); return 1; @@ -876,7 +876,7 @@ pub unsafe extern "C" fn rs_dns_tx_get_query_rrtype(tx: &mut DNSTransaction, if let &Some(ref request) = &tx.request { if (i as usize) < request.queries.len() { let query = &request.queries[i as usize]; - if query.name.len() > 0 { + if !query.name.is_empty() { *rrtype = query.rrtype; return 1; } diff --git a/rust/src/dns/log.rs b/rust/src/dns/log.rs index fe3ff2f9d5..038e12753f 100644 --- a/rust/src/dns/log.rs +++ b/rust/src/dns/log.rs @@ -514,7 +514,7 @@ fn dns_log_json_answer(js: &mut JsonBuilder, response: &DNSResponse, flags: u64) } js.set_string("rcode", &dns_rcode_string(header.flags))?; - if response.answers.len() > 0 { + if !response.answers.is_empty() { let mut js_answers = JsonBuilder::new_array(); // For grouped answers we use a HashMap keyed by the rrtype. @@ -601,7 +601,7 @@ fn dns_log_json_answer(js: &mut JsonBuilder, response: &DNSResponse, flags: u64) } - if response.authorities.len() > 0 { + if !response.authorities.is_empty() { js.open_array("authorities")?; for auth in &response.authorities { let auth_detail = dns_log_json_answer_detail(auth)?; diff --git a/rust/src/dns/parser.rs b/rust/src/dns/parser.rs index 94f06dbc89..dbdca79c6e 100644 --- a/rust/src/dns/parser.rs +++ b/rust/src/dns/parser.rs @@ -57,7 +57,7 @@ pub fn dns_parse_name<'a, 'b>(start: &'b [u8], message: &'b [u8]) -> IResult<&'b let mut count = 0; loop { - if pos.len() == 0 { + if pos.is_empty() { break; } @@ -68,7 +68,7 @@ pub fn dns_parse_name<'a, 'b>(start: &'b [u8], message: &'b [u8]) -> IResult<&'b break; } else if len & 0b1100_0000 == 0 { let (rem, label) = length_data(be_u8)(pos)?; - if name.len() > 0 { + if !name.is_empty() { name.push(b'.'); } name.extend(label); @@ -477,7 +477,7 @@ mod tests { // For now we have some remainder data as there is an // additional record type we don't parse yet. - assert!(rem.len() > 0); + assert!(!rem.is_empty()); assert_eq!(request.header, DNSHeader { tx_id: 0x8d32, @@ -602,7 +602,7 @@ mod tests { // For now we have some remainder data as there is an // additional record type we don't parse yet. - assert!(rem.len() > 0); + assert!(!rem.is_empty()); assert_eq!(response.header, DNSHeader{ tx_id: 0x8295, diff --git a/rust/src/filecontainer.rs b/rust/src/filecontainer.rs index d00ae0fa6c..b6eabd4c1e 100644 --- a/rust/src/filecontainer.rs +++ b/rust/src/filecontainer.rs @@ -95,7 +95,7 @@ impl FileContainer { pub fn file_append(&mut self, track_id: &u32, data: &[u8], is_gap: bool) -> i32 { SCLogDebug!("FILECONTAINER: append {}", data.len()); - if data.len() == 0 { + if data.is_empty() { return 0 } match unsafe {SC} { diff --git a/rust/src/http2/detect.rs b/rust/src/http2/detect.rs index e1ba9206de..2cdb60449f 100644 --- a/rust/src/http2/detect.rs +++ b/rust/src/http2/detect.rs @@ -769,7 +769,7 @@ pub unsafe extern "C" fn rs_http2_tx_get_headers( } } } - if vec.len() > 0 { + if !vec.is_empty() { tx.escaped.push(vec); let idx = tx.escaped.len() - 1; let value = &tx.escaped[idx]; @@ -801,7 +801,7 @@ pub unsafe extern "C" fn rs_http2_tx_get_headers_raw( } } } - if vec.len() > 0 { + if !vec.is_empty() { tx.escaped.push(vec); let idx = tx.escaped.len() - 1; let value = &tx.escaped[idx]; diff --git a/rust/src/http2/http2.rs b/rust/src/http2/http2.rs index db42839848..c6ce7de683 100644 --- a/rust/src/http2/http2.rs +++ b/rust/src/http2/http2.rs @@ -849,7 +849,7 @@ impl HTTP2State { match parser::http2_parse_frame_headers(input, hflags, dyn_headers) { Ok((hrem, hs)) => { self.process_headers(&hs.blocks, dir); - if hrem.len() > 0 { + if !hrem.is_empty() { SCLogDebug!("Remaining data for HTTP2 headers"); self.set_event(HTTP2Event::ExtraHeaderData); } @@ -889,7 +889,7 @@ impl HTTP2State { fn parse_frames( &mut self, mut input: &[u8], il: usize, dir: Direction, flow: *const Flow, ) -> AppLayerResult { - while input.len() > 0 { + while !input.is_empty() { match parser::http2_parse_frame_header(input) { Ok((rem, head)) => { let hl = head.length as usize; diff --git a/rust/src/http2/parser.rs b/rust/src/http2/parser.rs index 5314308bc5..90b7ba6394 100644 --- a/rust/src/http2/parser.rs +++ b/rust/src/http2/parser.rs @@ -293,7 +293,7 @@ fn http2_frame_header_static(n: u64, dyn_headers: &HTTP2DynTable) -> Option ("www-authenticate", ""), _ => ("", ""), }; - if name.len() > 0 { + if !name.is_empty() { return Some(HTTP2FrameHeaderBlock { name: name.as_bytes().to_vec(), value: value.as_bytes().to_vec(), @@ -456,7 +456,7 @@ fn http2_parse_headers_block_literal_incindex<'a>( } else { dyn_headers.table.push(headcopy); } - while dyn_headers.current_size > dyn_headers.max_size && dyn_headers.table.len() > 0 + while dyn_headers.current_size > dyn_headers.max_size && !dyn_headers.table.is_empty() { dyn_headers.current_size -= 32 + dyn_headers.table[0].name.len() + dyn_headers.table[0].value.len(); @@ -539,7 +539,7 @@ fn http2_parse_headers_block_dynamic_size<'a>( if (maxsize2 as usize) < dyn_headers.max_size { //dyn_headers.max_size is updated later with all headers //may evict entries - while dyn_headers.current_size > (maxsize2 as usize) && dyn_headers.table.len() > 0 { + while dyn_headers.current_size > (maxsize2 as usize) && !dyn_headers.table.is_empty() { // we check dyn_headers.table as we may be in best effort // because the previous maxsize was too big for us to retain all the headers dyn_headers.current_size -= @@ -593,7 +593,7 @@ fn http2_parse_headers_blocks<'a>( ) -> IResult<&'a [u8], Vec> { let mut blocks = Vec::new(); let mut i3 = input; - while i3.len() > 0 { + while !i3.is_empty() { match http2_parse_headers_block(i3, dyn_headers) { Ok((rem, b)) => { blocks.push(b); diff --git a/rust/src/ike/detect.rs b/rust/src/ike/detect.rs index db5f1b7711..89e4085695 100644 --- a/rust/src/ike/detect.rs +++ b/rust/src/ike/detect.rs @@ -149,7 +149,7 @@ pub extern "C" fn rs_ike_state_get_sa_attribute( if let Ok(sa) = sa_type_s { if tx.ike_version == 1 { - if tx.hdr.ikev1_transforms.len() >= 1 { + if !tx.hdr.ikev1_transforms.is_empty() { // there should be only one chosen server_transform, check event if let Some(server_transform) = tx.hdr.ikev1_transforms.first() { for attr in server_transform { diff --git a/rust/src/ike/ike.rs b/rust/src/ike/ike.rs index 8c58fdd9b1..534c1232b4 100644 --- a/rust/src/ike/ike.rs +++ b/rust/src/ike/ike.rs @@ -199,7 +199,7 @@ impl IKEState { fn handle_input(&mut self, input: &[u8], direction: Direction) -> AppLayerResult { // We're not interested in empty requests. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } diff --git a/rust/src/ike/ikev1.rs b/rust/src/ike/ikev1.rs index d3be063c69..9b77371a52 100644 --- a/rust/src/ike/ikev1.rs +++ b/rust/src/ike/ikev1.rs @@ -57,7 +57,7 @@ impl Ikev1ParticipantData { ) { self.key_exchange = key_exchange.clone(); self.nonce = nonce.clone(); - if self.nb_transforms == 0 && transforms.len() > 0 { + if self.nb_transforms == 0 && !transforms.is_empty() { self.transform.extend(transforms[0].iter().cloned()); } self.nb_transforms += transforms.len() as u64; @@ -146,7 +146,7 @@ pub fn handle_ikev1( ); } - if rem.len() > 0 { + if !rem.is_empty() { // more data left unread than should be SCLogDebug!("Unread Payload Data"); state.set_event(IkeEvent::PayloadExtraData); diff --git a/rust/src/ike/logger.rs b/rust/src/ike/logger.rs index 042fdae4cd..cc5705f580 100644 --- a/rust/src/ike/logger.rs +++ b/rust/src/ike/logger.rs @@ -138,7 +138,7 @@ fn log_ikev1(state: &IKEState, tx: &IKETransaction, jb: &mut JsonBuilder) -> Res // client data jb.open_object("client")?; - if state.ikev1_container.client.key_exchange.len() > 0 { + if !state.ikev1_container.client.key_exchange.is_empty() { jb.set_string( "key_exchange_payload", &state.ikev1_container.client.key_exchange, @@ -149,7 +149,7 @@ fn log_ikev1(state: &IKEState, tx: &IKETransaction, jb: &mut JsonBuilder) -> Res jb.set_uint("key_exchange_payload_length", client_key_length / 2)?; } } - if state.ikev1_container.client.nonce.len() > 0 { + if !state.ikev1_container.client.nonce.is_empty() { jb.set_string("nonce_payload", &state.ikev1_container.client.nonce)?; if let Ok(client_nonce_length) = u64::try_from(state.ikev1_container.client.nonce.len()) { @@ -157,7 +157,7 @@ fn log_ikev1(state: &IKEState, tx: &IKETransaction, jb: &mut JsonBuilder) -> Res } } - if tx.direction == Direction::ToServer && tx.hdr.ikev1_transforms.len() > 0 { + if tx.direction == Direction::ToServer && !tx.hdr.ikev1_transforms.is_empty() { jb.open_array("proposals")?; for client_transform in &tx.hdr.ikev1_transforms { jb.start_object()?; @@ -170,7 +170,7 @@ fn log_ikev1(state: &IKEState, tx: &IKETransaction, jb: &mut JsonBuilder) -> Res // server data jb.open_object("server")?; - if state.ikev1_container.server.key_exchange.len() > 0 { + if !state.ikev1_container.server.key_exchange.is_empty() { jb.set_string( "key_exchange_payload", &state.ikev1_container.server.key_exchange, @@ -181,7 +181,7 @@ fn log_ikev1(state: &IKEState, tx: &IKETransaction, jb: &mut JsonBuilder) -> Res jb.set_uint("key_exchange_payload_length", server_key_length / 2)?; } } - if state.ikev1_container.server.nonce.len() > 0 { + if !state.ikev1_container.server.nonce.is_empty() { jb.set_string("nonce_payload", &state.ikev1_container.server.nonce)?; if let Ok(server_nonce_length) = u64::try_from(state.ikev1_container.server.nonce.len()) { @@ -190,7 +190,7 @@ fn log_ikev1(state: &IKEState, tx: &IKETransaction, jb: &mut JsonBuilder) -> Res } jb.close()?; // server - if tx.hdr.ikev1_header.vendor_ids.len() > 0 { + if !tx.hdr.ikev1_header.vendor_ids.is_empty() { jb.open_array("vendor_ids")?; for vendor in &tx.hdr.ikev1_header.vendor_ids { jb.append_string(vendor)?; diff --git a/rust/src/krb/krb5.rs b/rust/src/krb/krb5.rs index d1fabaead1..0399733c06 100644 --- a/rust/src/krb/krb5.rs +++ b/rust/src/krb/krb5.rs @@ -437,7 +437,7 @@ pub unsafe extern "C" fn rs_krb5_parse_request_tcp(_flow: *const core::Flow, } }; let mut cur_i = tcp_buffer; - while cur_i.len() > 0 { + while !cur_i.is_empty() { if state.record_ts == 0 { match be_u32(cur_i) as IResult<&[u8],u32> { Ok((rem,record)) => { @@ -495,7 +495,7 @@ pub unsafe extern "C" fn rs_krb5_parse_response_tcp(_flow: *const core::Flow, } }; let mut cur_i = tcp_buffer; - while cur_i.len() > 0 { + while !cur_i.is_empty() { if state.record_tc == 0 { match be_u32(cur_i) as IResult<&[u8],_> { Ok((rem,record)) => { diff --git a/rust/src/mime/mod.rs b/rust/src/mime/mod.rs index fa69da4192..185aadcd05 100644 --- a/rust/src/mime/mod.rs +++ b/rust/src/mime/mod.rs @@ -56,7 +56,7 @@ pub fn mime_parse_header_token(input: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> { fn mime_parse_header_tokens(input: &[u8]) -> IResult<&[u8], MIMEHeaderTokens> { let (mut input, _) = take_until_and_consume(b";")(input)?; let mut tokens = HashMap::new(); - while input.len() > 0 { + while !input.is_empty() { match mime_parse_header_token(input) { Ok((rem, t)) => { tokens.insert(t.0, t.1); diff --git a/rust/src/modbus/modbus.rs b/rust/src/modbus/modbus.rs index 3dd6a56017..2ffc24f858 100644 --- a/rust/src/modbus/modbus.rs +++ b/rust/src/modbus/modbus.rs @@ -185,7 +185,7 @@ impl ModbusState { pub fn parse(&mut self, input: &[u8], direction: Direction) -> AppLayerResult { let mut rest = input; - while rest.len() > 0 { + while !rest.is_empty() { match MODBUS_PARSER.parse(rest, direction.clone()) { Ok((inner_rest, Some(mut msg))) => { match direction { @@ -316,7 +316,7 @@ pub unsafe extern "C" fn rs_modbus_parse_request( _data: *const std::os::raw::c_void, ) -> AppLayerResult { let buf = stream_slice.as_slice(); - if buf.len() == 0 { + if buf.is_empty() { if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS) > 0 { return AppLayerResult::ok(); } else { @@ -335,7 +335,7 @@ pub unsafe extern "C" fn rs_modbus_parse_response( _data: *const std::os::raw::c_void, ) -> AppLayerResult { let buf = stream_slice.as_slice(); - if buf.len() == 0 { + if buf.is_empty() { if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TC) > 0 { return AppLayerResult::ok(); } else { diff --git a/rust/src/mqtt/detect.rs b/rust/src/mqtt/detect.rs index 8e11abde7d..ba0f6409a5 100644 --- a/rust/src/mqtt/detect.rs +++ b/rust/src/mqtt/detect.rs @@ -131,7 +131,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_connect_clientid( for msg in tx.msg.iter() { if let MQTTOperation::CONNECT(ref cv) = msg.op { let p = &cv.client_id; - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -151,7 +151,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_connect_username( for msg in tx.msg.iter() { if let MQTTOperation::CONNECT(ref cv) = msg.op { if let Some(p) = &cv.username { - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -173,7 +173,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_connect_password( for msg in tx.msg.iter() { if let MQTTOperation::CONNECT(ref cv) = msg.op { if let Some(p) = &cv.password { - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -194,7 +194,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_connect_willtopic( for msg in tx.msg.iter() { if let MQTTOperation::CONNECT(ref cv) = msg.op { if let Some(p) = &cv.will_topic { - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -216,7 +216,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_connect_willmessage( for msg in tx.msg.iter() { if let MQTTOperation::CONNECT(ref cv) = msg.op { if let Some(p) = &cv.will_message { - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -251,7 +251,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_publish_topic( for msg in tx.msg.iter() { if let MQTTOperation::PUBLISH(ref pubv) = msg.op { let p = &pubv.topic; - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -272,7 +272,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_publish_message( for msg in tx.msg.iter() { if let MQTTOperation::PUBLISH(ref pubv) = msg.op { let p = &pubv.message; - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -295,7 +295,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_subscribe_topic( if let MQTTOperation::SUBSCRIBE(ref subv) = msg.op { if (i as usize) < subv.topics.len() + offset { let topic = &subv.topics[(i as usize) - offset]; - if topic.topic_name.len() > 0 { + if !topic.topic_name.is_empty() { *len = topic.topic_name.len() as u32; *buf = topic.topic_name.as_ptr(); return 1; @@ -321,7 +321,7 @@ pub unsafe extern "C" fn rs_mqtt_tx_get_unsubscribe_topic( if let MQTTOperation::UNSUBSCRIBE(ref unsubv) = msg.op { if (i as usize) < unsubv.topics.len() + offset { let topic = &unsubv.topics[(i as usize) - offset]; - if topic.len() > 0 { + if !topic.is_empty() { *len = topic.len() as u32; *buf = topic.as_ptr(); return 1; diff --git a/rust/src/mqtt/logger.rs b/rust/src/mqtt/logger.rs index 22fc7de079..09b14fe25d 100644 --- a/rust/src/mqtt/logger.rs +++ b/rust/src/mqtt/logger.rs @@ -233,7 +233,7 @@ fn log_mqtt(tx: &MQTTTransaction, flags: u32, js: &mut JsonBuilder) -> Result<() log_mqtt_header(js, &msg.header)?; js.set_uint("message_id", unsuback.message_id as u64)?; if let Some(codes) = &unsuback.reason_codes { - if codes.len() > 0 { + if !codes.is_empty() { js.open_array("reason_codes")?; for t in codes { js.append_uint(*t as u64)?; diff --git a/rust/src/mqtt/mqtt.rs b/rust/src/mqtt/mqtt.rs index 94b7956f7f..9dfef0cfe3 100644 --- a/rust/src/mqtt/mqtt.rs +++ b/rust/src/mqtt/mqtt.rs @@ -423,7 +423,7 @@ impl MQTTState { fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { let mut current = input; - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -450,7 +450,7 @@ impl MQTTState { } } - while current.len() > 0 { + while !current.is_empty() { SCLogDebug!("request: handling {}", current.len()); match parse_message(current, self.protocol_version, self.max_msg_len) { Ok((rem, msg)) => { @@ -498,7 +498,7 @@ impl MQTTState { fn parse_response(&mut self, input: &[u8]) -> AppLayerResult { let mut current = input; - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -524,7 +524,7 @@ impl MQTTState { } } - while current.len() > 0 { + while !current.is_empty() { SCLogDebug!("response: handling {}", current.len()); match parse_message(current, self.protocol_version, self.max_msg_len as usize) { Ok((rem, msg)) => { diff --git a/rust/src/mqtt/parser.rs b/rust/src/mqtt/parser.rs index fb938fb9d5..190f88d2c4 100644 --- a/rust/src/mqtt/parser.rs +++ b/rust/src/mqtt/parser.rs @@ -114,7 +114,7 @@ fn parse_properties(input: &[u8], precond: bool) -> IResult<&[u8], Option::new(); let (rem, mut newrem) = take(proplen as usize)(rem)?; - while newrem.len() > 0 { + while !newrem.is_empty() { match parse_property(newrem) { Ok((rem2, val)) => { props.push(val); diff --git a/rust/src/nfs/log.rs b/rust/src/nfs/log.rs index 66eda9fd64..f252cf2cb4 100644 --- a/rust/src/nfs/log.rs +++ b/rust/src/nfs/log.rs @@ -99,7 +99,7 @@ fn nfs_common_header(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder let file_name = String::from_utf8_lossy(&tx.file_name); js.set_string("filename", &file_name)?; - if tx.file_handle.len() > 0 { + if !tx.file_handle.is_empty() { //js.set_string("handle", &nfs_handle2hex(&tx.file_handle)); let c = nfs_handle2crc(&tx.file_handle); let s = format!("{:x}", c); diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index 76e8a2180f..a96e63f972 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -466,7 +466,7 @@ impl NFSState { mytx.response_done = true; mytx.rpc_response_status = rpc_status; mytx.nfs_response_status = nfs_status; - if mytx.file_handle.len() == 0 && resp_handle.len() > 0 { + if mytx.file_handle.is_empty() && !resp_handle.is_empty() { mytx.file_handle = resp_handle.to_vec(); } @@ -1212,14 +1212,14 @@ impl NFSState { } cur_i = &cur_i[consumed as usize..]; } - if cur_i.len() == 0 { + if cur_i.is_empty() { return AppLayerResult::ok(); } if self.ts_gap { SCLogDebug!("TS trying to catch up after GAP (input {})", cur_i.len()); let mut _cnt = 0; - while cur_i.len() > 0 { + while !cur_i.is_empty() { _cnt += 1; match nfs_probe(cur_i, Direction::ToServer) { 1 => { @@ -1234,7 +1234,7 @@ impl NFSState { }, -1 => { cur_i = &cur_i[1..]; - if cur_i.len() == 0 { + if cur_i.is_empty() { SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", _cnt); } }, @@ -1246,7 +1246,7 @@ impl NFSState { SCLogDebug!("TS GAP handling done (input {})", cur_i.len()); } - while cur_i.len() > 0 { // min record size + while !cur_i.is_empty() { // min record size self.add_rpc_tcp_ts_pdu(flow, stream_slice, cur_i, cur_i.len() as i64); match parse_rpc_request_partial(cur_i) { Ok((_, ref rpc_phdr)) => { @@ -1376,14 +1376,14 @@ impl NFSState { } cur_i = &cur_i[consumed as usize..]; } - if cur_i.len() == 0 { + if cur_i.is_empty() { return AppLayerResult::ok(); } if self.tc_gap { SCLogDebug!("TC trying to catch up after GAP (input {})", cur_i.len()); let mut _cnt = 0; - while cur_i.len() > 0 { + while !cur_i.is_empty() { _cnt += 1; match nfs_probe(cur_i, Direction::ToClient) { 1 => { @@ -1398,7 +1398,7 @@ impl NFSState { }, -1 => { cur_i = &cur_i[1..]; - if cur_i.len() == 0 { + if cur_i.is_empty() { SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", _cnt); } }, @@ -1410,7 +1410,7 @@ impl NFSState { SCLogDebug!("TC GAP handling done (input {})", cur_i.len()); } - while cur_i.len() > 0 { + while !cur_i.is_empty() { self.add_rpc_tcp_tc_pdu(flow, stream_slice, cur_i, cur_i.len() as i64); match parse_rpc_packet_header(cur_i) { Ok((_, ref rpc_phdr)) => { @@ -1473,7 +1473,7 @@ impl NFSState { let input = stream_slice.as_slice(); SCLogDebug!("parse_udp_ts ({})", input.len()); self.add_rpc_udp_ts_pdu(flow, stream_slice, input, input.len() as i64); - if input.len() > 0 { + if !input.is_empty() { match parse_rpc_udp_request(input) { Ok((_, ref rpc_record)) => { self.is_udp = true; @@ -1505,7 +1505,7 @@ impl NFSState { let input = stream_slice.as_slice(); SCLogDebug!("parse_udp_tc ({})", input.len()); self.add_rpc_udp_tc_pdu(flow, stream_slice, input, input.len() as i64); - if input.len() > 0 { + if !input.is_empty() { match parse_rpc_udp_reply(input) { Ok((_, ref rpc_record)) => { self.is_udp = true; diff --git a/rust/src/nfs/nfs4.rs b/rust/src/nfs/nfs4.rs index 5c3df56364..afa96e745e 100644 --- a/rust/src/nfs/nfs4.rs +++ b/rust/src/nfs/nfs4.rs @@ -376,7 +376,7 @@ impl NFSState { } } &Nfs4ResponseContent::PutRootFH(s) => { - if s == NFS4_OK && xidmap.file_name.len() == 0 { + if s == NFS4_OK && xidmap.file_name.is_empty() { xidmap.file_name = b"".to_vec(); SCLogDebug!("filename {:?}", xidmap.file_name); } diff --git a/rust/src/pgsql/pgsql.rs b/rust/src/pgsql/pgsql.rs index 8fe69e6add..30e4927b8c 100644 --- a/rust/src/pgsql/pgsql.rs +++ b/rust/src/pgsql/pgsql.rs @@ -301,7 +301,7 @@ impl PgsqlState { fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { // We're not interested in empty requests. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -320,7 +320,7 @@ impl PgsqlState { } let mut start = input; - while start.len() > 0 { + while !start.is_empty() { SCLogDebug!( "In 'parse_request' State Progress is: {:?}", &self.state_progress @@ -437,7 +437,7 @@ impl PgsqlState { fn parse_response(&mut self, input: &[u8], flow: *const Flow) -> AppLayerResult { // We're not interested in empty responses. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -453,7 +453,7 @@ impl PgsqlState { } let mut start = input; - while start.len() > 0 { + while !start.is_empty() { match PgsqlState::state_based_resp_parsing(self.state_progress, start) { Ok((rem, response)) => { start = rem; diff --git a/rust/src/quic/logger.rs b/rust/src/quic/logger.rs index 77429ae118..e03ebdd6bf 100644 --- a/rust/src/quic/logger.rs +++ b/rust/src/quic/logger.rs @@ -100,7 +100,7 @@ fn log_template(tx: &QuicTransaction, js: &mut JsonBuilder) -> Result<(), JsonEr js.set_string("ua", &String::from_utf8_lossy(ua))?; } } - if tx.cyu.len() > 0 { + if !tx.cyu.is_empty() { js.open_array("cyu")?; for cyu in &tx.cyu { js.start_object()?; @@ -122,7 +122,7 @@ fn log_template(tx: &QuicTransaction, js: &mut JsonBuilder) -> Result<(), JsonEr js.set_string("string", ja3)?; js.close()?; } - if tx.extv.len() > 0 { + if !tx.extv.is_empty() { js.open_array("extensions")?; for e in &tx.extv { js.start_object()?; @@ -132,7 +132,7 @@ fn log_template(tx: &QuicTransaction, js: &mut JsonBuilder) -> Result<(), JsonEr } js.set_uint("type", etype.into())?; - if e.values.len() > 0 { + if !e.values.is_empty() { js.open_array("values")?; for i in 0..e.values.len() { js.append_string(&String::from_utf8_lossy(&e.values[i]))?; diff --git a/rust/src/quic/quic.rs b/rust/src/quic/quic.rs index 37c14ad9ad..2dfe2e608f 100644 --- a/rust/src/quic/quic.rs +++ b/rust/src/quic/quic.rs @@ -229,7 +229,7 @@ impl QuicState { Frame::Crypto(c) => { ja3 = Some(c.ja3.clone()); for e in &c.extv { - if e.etype == TlsExtensionType::ServerName && e.values.len() > 0 { + if e.etype == TlsExtensionType::ServerName && !e.values.is_empty() { sni = Some(e.values[0].to_vec()); } } @@ -257,7 +257,7 @@ impl QuicState { fn parse(&mut self, input: &[u8], to_server: bool) -> bool { // so as to loop over multiple quic headers in one packet let mut buf = input; - while buf.len() > 0 { + while !buf.is_empty() { match QuicHeader::from_bytes(buf, DEFAULT_DCID_LEN) { Ok((rest, header)) => { if (to_server && self.hello_ts) || (!to_server && self.hello_tc) { diff --git a/rust/src/rdp/log.rs b/rust/src/rdp/log.rs index a9bba49320..1fe87839ba 100644 --- a/rust/src/rdp/log.rs +++ b/rust/src/rdp/log.rs @@ -226,7 +226,7 @@ fn mcs_req_to_json(mcs: &McsConnectRequest, js: &mut JsonBuilder) -> Result<(), &windows::os_to_string(&client.client_build, &unknown), )?; - if client.client_name.len() > 0 { + if !client.client_name.is_empty() { js.set_string("client_name", &client.client_name)?; } @@ -242,7 +242,7 @@ fn mcs_req_to_json(mcs: &McsConnectRequest, js: &mut JsonBuilder) -> Result<(), js.set_uint("function_keys", client.keyboard_function_key as u64)?; } - if client.ime_file_name.len() > 0 { + if !client.ime_file_name.is_empty() { js.set_string("ime", &client.ime_file_name)?; } @@ -315,7 +315,7 @@ fn mcs_req_to_json(mcs: &McsConnectRequest, js: &mut JsonBuilder) -> Result<(), } if let Some(ref id) = client.client_dig_product_id { - if id.len() > 0 { + if !id.is_empty() { js.set_string("id", id)?; } } @@ -361,7 +361,7 @@ fn mcs_req_to_json(mcs: &McsConnectRequest, js: &mut JsonBuilder) -> Result<(), } McsConnectRequestChild::CsNet(ref net) => { - if net.channels.len() > 0 { + if !net.channels.is_empty() { js.open_array("channels")?; for channel in &net.channels { js.append_string(channel)?; diff --git a/rust/src/rdp/parser.rs b/rust/src/rdp/parser.rs index fcccd00827..8d69827bf9 100644 --- a/rust/src/rdp/parser.rs +++ b/rust/src/rdp/parser.rs @@ -520,7 +520,7 @@ fn parse_x224_connection_request(input: &[u8]) -> IResult<&[u8], X224ConnectionR }; let (j1, cookie) = { - if data.len() > 0 { + if !data.is_empty() { match opt(parse_rdp_cookie)(data) { Ok((remainder, opt)) => (remainder, opt), Err(e) => return Err(e), @@ -531,7 +531,7 @@ fn parse_x224_connection_request(input: &[u8]) -> IResult<&[u8], X224ConnectionR }; let (j2, negotiation_request) = { - if j1.len() > 0 { + if !j1.is_empty() { match opt(parse_negotiation_request)(j1) { Ok((remainder, opt)) => (remainder, opt), Err(e) => return Err(e), @@ -782,7 +782,7 @@ fn parse_mcs_connect(input: &[u8]) -> IResult<&[u8], McsConnectRequest, RdpError Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)), Err(Err::Failure(_)) | Err(Err::Error(_)) => break, }; - if remainder.len() == 0 { + if remainder.is_empty() { break; } } diff --git a/rust/src/rdp/rdp.rs b/rust/src/rdp/rdp.rs index e931ed2368..d150488881 100644 --- a/rust/src/rdp/rdp.rs +++ b/rust/src/rdp/rdp.rs @@ -176,7 +176,7 @@ impl RdpState { let mut available = input; loop { - if available.len() == 0 { + if available.is_empty() { return AppLayerResult::ok(); } if self.tls_parsing { @@ -269,7 +269,7 @@ impl RdpState { let mut available = input; loop { - if available.len() == 0 { + if available.is_empty() { return AppLayerResult::ok(); } if self.tls_parsing { @@ -400,7 +400,7 @@ pub unsafe extern "C" fn rs_rdp_state_tx_free(state: *mut std::os::raw::c_void, /// probe for T.123 type identifier, as each message is encapsulated in T.123 fn probe_rdp(input: &[u8]) -> bool { - input.len() > 0 && input[0] == TpktVersion::T123 as u8 + !input.is_empty() && input[0] == TpktVersion::T123 as u8 } /// probe for T.123 message, whether to client or to server @@ -424,7 +424,7 @@ pub unsafe extern "C" fn rs_rdp_probe_ts_tc( /// probe for TLS fn probe_tls_handshake(input: &[u8]) -> bool { - input.len() > 0 && input[0] == u8::from(TlsRecordType::Handshake) + !input.is_empty() && input[0] == u8::from(TlsRecordType::Handshake) } // diff --git a/rust/src/rfb/detect.rs b/rust/src/rfb/detect.rs index d30014a139..7cfd7776b3 100644 --- a/rust/src/rfb/detect.rs +++ b/rust/src/rfb/detect.rs @@ -28,7 +28,7 @@ pub unsafe extern "C" fn rs_rfb_tx_get_name( ) -> u8 { if let Some(ref r) = tx.tc_server_init { let p = &r.name; - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; diff --git a/rust/src/rfb/rfb.rs b/rust/src/rfb/rfb.rs index 60c0e4adb6..b17afba397 100644 --- a/rust/src/rfb/rfb.rs +++ b/rust/src/rfb/rfb.rs @@ -150,7 +150,7 @@ impl RFBState { fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { // We're not interested in empty requests. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -158,7 +158,7 @@ impl RFBState { let mut consumed = 0; SCLogDebug!("request_state {}, input_len {}", self.state, input.len()); loop { - if current.len() == 0 { + if current.is_empty() { return AppLayerResult::ok(); } match self.state { @@ -279,7 +279,7 @@ impl RFBState { fn parse_response(&mut self, input: &[u8]) -> AppLayerResult { // We're not interested in empty responses. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -287,7 +287,7 @@ impl RFBState { let mut consumed = 0; SCLogDebug!("response_state {}, response_len {}", self.state, input.len()); loop { - if current.len() == 0 { + if current.is_empty() { return AppLayerResult::ok(); } match self.state { diff --git a/rust/src/sip/detect.rs b/rust/src/sip/detect.rs index 7098ea54a3..63f636529a 100644 --- a/rust/src/sip/detect.rs +++ b/rust/src/sip/detect.rs @@ -29,7 +29,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_method( ) -> u8 { if let Some(ref r) = tx.request { let m = &r.method; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -50,7 +50,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_uri( ) -> u8 { if let Some(ref r) = tx.request { let p = &r.path; - if p.len() > 0 { + if !p.is_empty() { *buffer = p.as_ptr(); *buffer_len = p.len() as u32; return 1; @@ -74,7 +74,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_protocol( Direction::ToServer => { if let Some(ref r) = tx.request { let v = &r.version; - if v.len() > 0 { + if !v.is_empty() { *buffer = v.as_ptr(); *buffer_len = v.len() as u32; return 1; @@ -84,7 +84,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_protocol( Direction::ToClient => { if let Some(ref r) = tx.response { let v = &r.version; - if v.len() > 0 { + if !v.is_empty() { *buffer = v.as_ptr(); *buffer_len = v.len() as u32; return 1; @@ -107,7 +107,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_stat_code( ) -> u8 { if let Some(ref r) = tx.response { let c = &r.code; - if c.len() > 0 { + if !c.is_empty() { *buffer = c.as_ptr(); *buffer_len = c.len() as u32; return 1; @@ -128,7 +128,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_stat_msg( ) -> u8 { if let Some(ref r) = tx.response { let re = &r.reason; - if re.len() > 0 { + if !re.is_empty() { *buffer = re.as_ptr(); *buffer_len = re.len() as u32; return 1; @@ -148,7 +148,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_request_line( buffer_len: *mut u32, ) -> u8 { if let Some(ref r) = tx.request_line { - if r.len() > 0 { + if !r.is_empty() { *buffer = r.as_ptr(); *buffer_len = r.len() as u32; return 1; @@ -168,7 +168,7 @@ pub unsafe extern "C" fn rs_sip_tx_get_response_line( buffer_len: *mut u32, ) -> u8 { if let Some(ref r) = tx.response_line { - if r.len() > 0 { + if !r.is_empty() { *buffer = r.as_ptr(); *buffer_len = r.len() as u32; return 1; diff --git a/rust/src/smb/dcerpc.rs b/rust/src/smb/dcerpc.rs index b21c016a1a..2be850c528 100644 --- a/rust/src/smb/dcerpc.rs +++ b/rust/src/smb/dcerpc.rs @@ -268,7 +268,7 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState, is_bind = true; SCLogDebug!("SMB DCERPC {:?} BIND {:?}", dcer, bindr); - if bindr.ifaces.len() > 0 { + if !bindr.ifaces.is_empty() { let mut ifaces: Vec = Vec::new(); for i in bindr.ifaces { let x = if dcer.little_endian == true { @@ -470,7 +470,7 @@ pub fn smb_read_dcerpc_record<'b>(state: &mut SMBState, let mut malformed = false; - if data.len() == 0 { + if data.is_empty() { SCLogDebug!("weird: no DCERPC data"); // TODO // TODO set event? return false; diff --git a/rust/src/smb/detect.rs b/rust/src/smb/detect.rs index 4376a71749..f7a48d58aa 100644 --- a/rust/src/smb/detect.rs +++ b/rust/src/smb/detect.rs @@ -84,7 +84,7 @@ pub unsafe extern "C" fn rs_smb_tx_get_stub_data(tx: &mut SMBTransaction, } else { &x.stub_data_tc }; - if vref.len() > 0 { + if !vref.is_empty() { *buffer = vref.as_ptr(); *buffer_len = vref.len() as u32; return 1; diff --git a/rust/src/smb/log.rs b/rust/src/smb/log.rs index 4a2cb43b22..747606ed06 100644 --- a/rust/src/smb/log.rs +++ b/rust/src/smb/log.rs @@ -198,7 +198,7 @@ fn smb_common_header(jsb: &mut JsonBuilder, state: &SMBState, tx: &SMBTransactio Some(SMBTransactionTypeData::CREATE(ref x)) => { let mut name_raw = x.filename.to_vec(); name_raw.retain(|&i|i != 0x00); - if name_raw.len() > 0 { + if !name_raw.is_empty() { let name = String::from_utf8_lossy(&name_raw); if x.directory { jsb.set_string("directory", &name)?; @@ -407,7 +407,7 @@ fn smb_common_header(jsb: &mut JsonBuilder, state: &SMBState, tx: &SMBTransactio Some(SMBTransactionTypeData::SETFILEPATHINFO(ref x)) => { let mut name_raw = x.filename.to_vec(); name_raw.retain(|&i|i != 0x00); - if name_raw.len() > 0 { + if !name_raw.is_empty() { let name = String::from_utf8_lossy(&name_raw); jsb.set_string("filename", &name)?; } else { diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index 35fb59bec2..90f520abe2 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -1360,13 +1360,13 @@ impl SMBState { } cur_i = &cur_i[consumed as usize..]; } - if cur_i.len() == 0 { + if cur_i.is_empty() { return AppLayerResult::ok(); } // gap if self.ts_gap { SCLogDebug!("TS trying to catch up after GAP (input {})", cur_i.len()); - while cur_i.len() > 0 { // min record size + while !cur_i.is_empty() { // min record size match search_smb_record(cur_i) { Ok((_, pg)) => { SCLogDebug!("smb record found"); @@ -1394,7 +1394,7 @@ impl SMBState { } } } - while cur_i.len() > 0 { // min record size + while !cur_i.is_empty() { // min record size match parse_nbss_record(cur_i) { Ok((rem, ref nbss_hdr)) => { SCLogDebug!("nbss frame offset {} len {}", stream_slice.offset_from(cur_i), cur_i.len() - rem.len()); @@ -1435,7 +1435,7 @@ impl SMBState { } } else if smb.version == 0xfe_u8 { // SMB2 let mut nbss_data = nbss_hdr.data; - while nbss_data.len() > 0 { + while !nbss_data.is_empty() { SCLogDebug!("SMBv2 record"); match parse_smb2_request_record(nbss_data) { Ok((nbss_data_rem, ref smb_record)) => { @@ -1467,7 +1467,7 @@ impl SMBState { } else if smb.version == 0xfd_u8 { // SMB3 transform let mut nbss_data = nbss_hdr.data; - while nbss_data.len() > 0 { + while !nbss_data.is_empty() { SCLogDebug!("SMBv3 transform record"); match parse_smb3_transform_record(nbss_data) { Ok((nbss_data_rem, ref _smb3_record)) => { @@ -1692,13 +1692,13 @@ impl SMBState { } cur_i = &cur_i[consumed as usize..]; } - if cur_i.len() == 0 { + if cur_i.is_empty() { return AppLayerResult::ok(); } // gap if self.tc_gap { SCLogDebug!("TC trying to catch up after GAP (input {})", cur_i.len()); - while cur_i.len() > 0 { // min record size + while !cur_i.is_empty() { // min record size match search_smb_record(cur_i) { Ok((_, pg)) => { SCLogDebug!("smb record found"); @@ -1726,7 +1726,7 @@ impl SMBState { } } } - while cur_i.len() > 0 { // min record size + while !cur_i.is_empty() { // min record size match parse_nbss_record(cur_i) { Ok((rem, ref nbss_hdr)) => { SCLogDebug!("nbss record offset {} len {}", stream_slice.offset_from(cur_i), cur_i.len() - rem.len()); @@ -1761,7 +1761,7 @@ impl SMBState { } } else if smb.version == 0xfe_u8 { // SMB2 let mut nbss_data = nbss_hdr.data; - while nbss_data.len() > 0 { + while !nbss_data.is_empty() { SCLogDebug!("SMBv2 record"); match parse_smb2_response_record(nbss_data) { Ok((nbss_data_rem, ref smb_record)) => { @@ -1786,7 +1786,7 @@ impl SMBState { } } else if smb.version == 0xfd_u8 { // SMB3 transform let mut nbss_data = nbss_hdr.data; - while nbss_data.len() > 0 { + while !nbss_data.is_empty() { SCLogDebug!("SMBv3 transform record"); match parse_smb3_transform_record(nbss_data) { Ok((nbss_data_rem, ref _smb3_record)) => { diff --git a/rust/src/smb/smb1.rs b/rust/src/smb/smb1.rs index 5ca1da5207..ec24d7e1c0 100644 --- a/rust/src/smb/smb1.rs +++ b/rust/src/smb/smb1.rs @@ -433,7 +433,7 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command: let mut bad_dialects = false; let mut dialects : Vec> = Vec::new(); for d in &pr.dialects { - if d.len() == 0 { + if d.is_empty() { bad_dialects = true; continue; } else if d.len() == 1 { @@ -1126,7 +1126,7 @@ pub fn smb1_read_response_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>, an /// configured to do so, or if this is a tx especially /// for setting an event. fn smb1_request_record_generic<'b>(state: &mut SMBState, r: &SmbRecord<'b>, events: Vec) { - if smb1_create_new_tx(r.command) || events.len() > 0 { + if smb1_create_new_tx(r.command) || !events.is_empty() { let tx_key = SMBCommonHdr::from1(r, SMBHDR_TYPE_GENERICTX); let tx = state.new_generic_tx(1, r.command as u16, tx_key); tx.set_events(events); @@ -1149,7 +1149,7 @@ fn smb1_response_record_generic<'b>(state: &mut SMBState, r: &SmbRecord<'b>, eve }, None => {}, } - if events.len() > 0 { + if !events.is_empty() { let tx = state.new_generic_tx(1, r.command as u16, tx_key); tx.request_done = true; tx.response_done = true; diff --git a/rust/src/smb/smb2.rs b/rust/src/smb/smb2.rs index 28ff70a066..77e4f35fe0 100644 --- a/rust/src/smb/smb2.rs +++ b/rust/src/smb/smb2.rs @@ -188,7 +188,7 @@ pub fn smb2_read_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>) Some(n) => (n.name.to_vec(), n.is_pipe), _ => { (Vec::new(), false) }, }; - let mut is_dcerpc = if is_pipe || (share_name.len() == 0 && !is_pipe) { + let mut is_dcerpc = if is_pipe || (share_name.is_empty() && !is_pipe) { state.get_service_for_guid(&file_guid).1 } else { false @@ -196,7 +196,7 @@ pub fn smb2_read_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>) SCLogDebug!("SMBv2/READ: share_name {:?} is_pipe {} is_dcerpc {}", share_name, is_pipe, is_dcerpc); - if share_name.len() == 0 && !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"); if smb_dcerpc_probe(rd.data) == true { @@ -327,7 +327,7 @@ pub fn smb2_write_request_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>) Some(n) => { (n.name.to_vec(), n.is_pipe) }, _ => { (Vec::new(), false) }, }; - let mut is_dcerpc = if is_pipe || (share_name.len() == 0 && !is_pipe) { + let mut is_dcerpc = if is_pipe || (share_name.is_empty() && !is_pipe) { state.get_service_for_guid(wr.guid).1 } else { false @@ -336,7 +336,7 @@ pub fn smb2_write_request_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>) share_name, is_pipe, is_dcerpc); // if we missed the TREE connect we can't be sure if 'is_dcerpc' is correct - if share_name.len() == 0 && !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"); if smb_dcerpc_probe(wr.data) == true { diff --git a/rust/src/smb/smb_records.rs b/rust/src/smb/smb_records.rs index 1ee2248448..cc5b3cb7a2 100644 --- a/rust/src/smb/smb_records.rs +++ b/rust/src/smb/smb_records.rs @@ -27,7 +27,7 @@ pub fn smb_get_unicode_string(blob: &[u8]) -> IResult<&[u8], Vec, SmbError> SCLogDebug!("get_unicode_string: blob {} {:?}", blob.len(), blob); let mut name : Vec = Vec::new(); let mut c = blob; - while c.len() >= 1 { + while !c.is_empty() { if c.len() == 1 && c[0] == 0 { let rem = &c[1..]; SCLogDebug!("get_unicode_string: name {:?}", name); diff --git a/rust/src/snmp/log.rs b/rust/src/snmp/log.rs index bd04dec36d..06c22e81f6 100644 --- a/rust/src/snmp/log.rs +++ b/rust/src/snmp/log.rs @@ -59,7 +59,7 @@ fn snmp_log_response(jsb: &mut JsonBuilder, state: &mut SNMPState, tx: &mut SNMP }, _ => () } - if info.vars.len() > 0 { + if !info.vars.is_empty() { jsb.open_array("vars")?; for var in info.vars.iter() { jsb.append_string(&var.to_string())?; diff --git a/rust/src/ssh/detect.rs b/rust/src/ssh/detect.rs index d806bb1878..6aa18cdac7 100644 --- a/rust/src/ssh/detect.rs +++ b/rust/src/ssh/detect.rs @@ -27,7 +27,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_protocol( match direction.into() { Direction::ToServer => { let m = &tx.cli_hdr.protover; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -35,7 +35,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_protocol( } Direction::ToClient => { let m = &tx.srv_hdr.protover; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -56,7 +56,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_software( match direction.into() { Direction::ToServer => { let m = &tx.cli_hdr.swver; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -64,7 +64,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_software( } Direction::ToClient => { let m = &tx.srv_hdr.swver; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -88,7 +88,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh( match direction.into() { Direction::ToServer => { let m = &tx.cli_hdr.hassh; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -96,7 +96,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh( } Direction::ToClient => { let m = &tx.srv_hdr.hassh; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -120,7 +120,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh_string( match direction.into() { Direction::ToServer => { let m = &tx.cli_hdr.hassh_string; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; @@ -128,7 +128,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh_string( } Direction::ToClient => { let m = &tx.srv_hdr.hassh_string; - if m.len() > 0 { + if !m.is_empty() { *buffer = m.as_ptr(); *buffer_len = m.len() as u32; return 1; diff --git a/rust/src/ssh/logger.rs b/rust/src/ssh/logger.rs index 30823b61b6..9bc7d7c33f 100644 --- a/rust/src/ssh/logger.rs +++ b/rust/src/ssh/logger.rs @@ -19,39 +19,39 @@ use super::ssh::SSHTransaction; use crate::jsonbuilder::{JsonBuilder, JsonError}; fn log_ssh(tx: &SSHTransaction, js: &mut JsonBuilder) -> Result { - if tx.cli_hdr.protover.len() == 0 && tx.srv_hdr.protover.len() == 0 { + if tx.cli_hdr.protover.is_empty() && tx.srv_hdr.protover.is_empty() { return Ok(false); } - if tx.cli_hdr.protover.len() > 0 { + if !tx.cli_hdr.protover.is_empty() { js.open_object("client")?; js.set_string_from_bytes("proto_version", &tx.cli_hdr.protover)?; - if tx.cli_hdr.swver.len() > 0 { + if !tx.cli_hdr.swver.is_empty() { js.set_string_from_bytes("software_version", &tx.cli_hdr.swver)?; } - if tx.cli_hdr.hassh.len() > 0 || tx.cli_hdr.hassh_string.len() > 0 { + if !tx.cli_hdr.hassh.is_empty() || !tx.cli_hdr.hassh_string.is_empty() { js.open_object("hassh")?; - if tx.cli_hdr.hassh.len() > 0 { + if !tx.cli_hdr.hassh.is_empty() { js.set_string_from_bytes("hash", &tx.cli_hdr.hassh)?; } - if tx.cli_hdr.hassh_string.len() > 0 { + if !tx.cli_hdr.hassh_string.is_empty() { js.set_string_from_bytes("string", &tx.cli_hdr.hassh_string)?; } js.close()?; } js.close()?; } - if tx.srv_hdr.protover.len() > 0 { + if !tx.srv_hdr.protover.is_empty() { js.open_object("server")?; js.set_string_from_bytes("proto_version", &tx.srv_hdr.protover)?; - if tx.srv_hdr.swver.len() > 0 { + if !tx.srv_hdr.swver.is_empty() { js.set_string_from_bytes("software_version", &tx.srv_hdr.swver)?; } - if tx.srv_hdr.hassh.len() > 0 || tx.srv_hdr.hassh_string.len() > 0 { + if !tx.srv_hdr.hassh.is_empty() || !tx.srv_hdr.hassh_string.is_empty() { js.open_object("hassh")?; - if tx.srv_hdr.hassh.len() > 0 { + if !tx.srv_hdr.hassh.is_empty() { js.set_string_from_bytes("hash", &tx.srv_hdr.hassh)?; } - if tx.srv_hdr.hassh_string.len() > 0 { + if !tx.srv_hdr.hassh_string.is_empty() { js.set_string_from_bytes("string", &tx.srv_hdr.hassh_string)?; } js.close()?; diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index 2ac42e11db..912a6ba16d 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -151,7 +151,7 @@ impl SSHState { } } //parse records out of input - while input.len() > 0 { + while !input.is_empty() { match parser::ssh_parse_record(input) { Ok((rem, head)) => { SCLogDebug!("SSH valid record {}", head); @@ -274,7 +274,7 @@ impl SSHState { Ok((rem, line)) => { if let Ok((_, banner)) = parser::ssh_parse_banner(line) { hdr.protover.extend(banner.protover); - if banner.swver.len() > 0 { + if !banner.swver.is_empty() { hdr.swver.extend(banner.swver); } hdr.flags = SSHConnectionState::SshStateBannerDone; @@ -310,7 +310,7 @@ impl SSHState { ); if let Ok((_, banner)) = parser::ssh_parse_banner(input) { hdr.protover.extend(banner.protover); - if banner.swver.len() > 0 { + if !banner.swver.is_empty() { hdr.swver.extend(banner.swver); } hdr.flags = SSHConnectionState::SshStateBannerWaitEol; diff --git a/rust/src/telnet/telnet.rs b/rust/src/telnet/telnet.rs index f9998cff85..416932c4c2 100644 --- a/rust/src/telnet/telnet.rs +++ b/rust/src/telnet/telnet.rs @@ -152,7 +152,7 @@ impl TelnetState { &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], ) -> AppLayerResult { // We're not interested in empty requests. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -170,7 +170,7 @@ impl TelnetState { } let mut start = input; - while start.len() > 0 { + while !start.is_empty() { if self.request_frame.is_none() { self.request_frame = Frame::new( flow, @@ -262,7 +262,7 @@ impl TelnetState { fn parse_response(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8]) -> AppLayerResult { // We're not interested in empty responses. - if input.len() == 0 { + if input.is_empty() { return AppLayerResult::ok(); } @@ -278,7 +278,7 @@ impl TelnetState { self.response_gap = false; } let mut start = input; - while start.len() > 0 { + 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); }