]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pgsql/parser: simplify response parsing
authorJuliana Fajardini <jufajardini@gmail.com>
Fri, 7 Feb 2025 20:57:50 +0000 (17:57 -0300)
committerVictor Julien <victor@inliniac.net>
Wed, 19 Feb 2025 08:21:36 +0000 (09:21 +0100)
The initial parsing for message type checking was more complex than
needed be.

Related to
Bug #5524

rust/src/pgsql/parser.rs

index 2656b48042875c54e40594353aba43e14ce692ac..d516c9ca5ffa1b094153c8191979114c89bbfb63 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2022 Open Information Security Foundation
+/* Copyright (C) 2022-2025 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -28,7 +28,7 @@ use nom7::error::{make_error, ErrorKind};
 use nom7::multi::{many1, many_m_n, many_till};
 use nom7::number::streaming::{be_i16, be_i32};
 use nom7::number::streaming::{be_u16, be_u32, be_u8};
-use nom7::sequence::{terminated, tuple};
+use nom7::sequence::terminated;
 use nom7::{Err, IResult};
 
 pub const PGSQL_LENGTH_FIELD: u32 = 4;
@@ -1137,8 +1137,8 @@ fn parse_notification_response(i: &[u8]) -> IResult<&[u8], PgsqlBEMessage> {
 }
 
 pub fn pgsql_parse_response(i: &[u8]) -> IResult<&[u8], PgsqlBEMessage> {
-    let (i, pseudo_header) = peek(tuple((be_u8, be_u32)))(i)?;
-    let (i, message) = match pseudo_header.0 {
+    let (i, tag) = peek(be_u8)(i)?;
+    let (i, message) = match tag {
         b'E' => pgsql_parse_error_response(i)?,
         b'K' => parse_backend_key_data_message(i)?,
         b'N' => pgsql_parse_notice_response(i)?,