]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ike: don't log duplicate attributes
authorJason Ish <jason.ish@oisf.net>
Thu, 16 Oct 2025 22:42:45 +0000 (16:42 -0600)
committerJason Ish <jason.ish@oisf.net>
Thu, 16 Oct 2025 22:54:15 +0000 (16:54 -0600)
Track what attributes have been logged and skip over duplicate
attributes to avoid having duplicate fields in the JSON object, which
is invalid JSON.

This is lossy, subsequent attributes are lost.

Ticket: #7923

rust/src/ike/logger.rs

index 823850142777cde6af8f74b7750ac71fed66f4b1..051162f13d6842005486e1ba25a02a632adc4527 100644 (file)
@@ -22,14 +22,24 @@ use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute};
 use crate::jsonbuilder::{JsonBuilder, JsonError};
 use num_traits::FromPrimitive;
 use std;
+use std::collections::HashSet;
 use std::convert::TryFrom;
 
 const LOG_EXTENDED: u32 = 0x01;
 
 fn add_attributes(transform: &Vec<SaAttribute>, js: &mut JsonBuilder) -> Result<(), JsonError> {
+    let mut logged: HashSet<String> = HashSet::new();
+
     for attribute in transform {
+        let key = attribute.attribute_type.to_string();
+
+        if logged.contains(&key) {
+            continue;
+        }
+        logged.insert(key.clone());
+
         js.set_string(
-            attribute.attribute_type.to_string().as_str(),
+            &key,
             attribute.attribute_value.to_string().as_str(),
         )?;