]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pgsql/logger: open json object from logger function
authorJuliana Fajardini <jufajardini@oisf.net>
Thu, 25 Apr 2024 01:13:35 +0000 (22:13 -0300)
committerVictor Julien <victor@inliniac.net>
Wed, 5 Jun 2024 16:00:35 +0000 (18:00 +0200)
Before, the JsonBuilder object for the pgsql event was being created
from the C-side function that actually called the Rust logger.

This resulted that if another module - such as the Json Alert called the
PGSQL logger, we wouldn't have the `pgsql` key present in the log output
- only its inner fields.

Bug #6983

rust/src/pgsql/logger.rs
src/output-json-pgsql.c

index 934b549a16710c70f82f0e84ec133222ad34ed33..bcfcb5a8e933fe289cf2bae3e62e70578735824f 100644 (file)
@@ -27,6 +27,7 @@ use std;
 pub const PGSQL_LOG_PASSWORDS: u32 = BIT_U32!(0);
 
 fn log_pgsql(tx: &PgsqlTransaction, flags: u32, js: &mut JsonBuilder) -> Result<(), JsonError> {
+    js.open_object("pgsql")?;
     js.set_uint("tx_id", tx.tx_id)?;
     if let Some(request) = &tx.request {
         js.set_object("request", &log_request(request, flags)?)?;
@@ -35,12 +36,14 @@ fn log_pgsql(tx: &PgsqlTransaction, flags: u32, js: &mut JsonBuilder) -> Result<
         // TODO Log anomaly event instead?
         js.set_bool("request", false)?;
         js.set_bool("response", false)?;
+        js.close()?;
         return Ok(());
     }
 
     if !tx.responses.is_empty() {
         js.set_object("response", &log_response_object(tx)?)?;
     }
+    js.close()?;
 
     Ok(())
 }
index 623077e8ad44a8cb2ed989fbb92176f130d18d69..d82602e351a7e19e37a1d7ada1845a612db3ca4f 100644 (file)
@@ -76,11 +76,9 @@ static int JsonPgsqlLogger(ThreadVars *tv, void *thread_data, const Packet *p, F
         return TM_ECODE_FAILED;
     }
 
-    jb_open_object(jb, "pgsql");
     if (!rs_pgsql_logger(txptr, thread->pgsqllog_ctx->flags, jb)) {
         goto error;
     }
-    jb_close(jb);
 
     OutputJsonBuilderBuffer(jb, thread->ctx);
     jb_free(jb);