From: Juliana Fajardini Date: Fri, 7 Feb 2025 20:57:50 +0000 (-0300) Subject: pgsql/parser: simplify response parsing X-Git-Tag: suricata-8.0.0-beta1~414 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=737fea751fa9bc8c5b50b242711ed6d827180fd2;p=thirdparty%2Fsuricata.git pgsql/parser: simplify response parsing The initial parsing for message type checking was more complex than needed be. Related to Bug #5524 --- diff --git a/rust/src/pgsql/parser.rs b/rust/src/pgsql/parser.rs index 2656b48042..d516c9ca5f 100644 --- a/rust/src/pgsql/parser.rs +++ b/rust/src/pgsql/parser.rs @@ -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)?,