Skip to content

Commit

Permalink
pgsql: fix probing functions
Browse files Browse the repository at this point in the history
Some non-pgsql traffic seen by Suricata is mistankenly identified as
pgsql, as the probing function is too generic. Now, if the parser sees
an unknown message type, even if it looks like pgsql, it will fail.

Bug OISF#6080
  • Loading branch information
jufajardini authored and victorjulien committed Dec 5, 2023
1 parent 1ac5d97 commit 4f85d06
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions rust/src/pgsql/pgsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Default for PgsqlState {
Self::new()
}
}

impl PgsqlState {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -563,8 +563,20 @@ pub unsafe extern "C" fn rs_pgsql_probing_parser_ts(
if input_len >= 1 && !input.is_null() {

let slice: &[u8] = build_slice!(input, input_len as usize);
if probe_ts(slice) {
return ALPROTO_PGSQL;

match parser::parse_request(slice) {
Ok((_, request)) => {
if let PgsqlFEMessage::UnknownMessageType(_) = request {
return ALPROTO_FAILED;
}
return ALPROTO_PGSQL;
}
Err(Err::Incomplete(_)) => {
return ALPROTO_UNKNOWN;
}
Err(_e) => {
return ALPROTO_FAILED;
}
}
}
return ALPROTO_UNKNOWN;
Expand All @@ -584,7 +596,10 @@ pub unsafe extern "C" fn rs_pgsql_probing_parser_tc(
}

match parser::pgsql_parse_response(slice) {
Ok((_, _response)) => {
Ok((_, response)) => {
if let PgsqlBEMessage::UnknownMessageType(_) = response {
return ALPROTO_FAILED;
}
return ALPROTO_PGSQL;
}
Err(Err::Incomplete(_)) => {
Expand Down

0 comments on commit 4f85d06

Please sign in to comment.