Skip to content

Commit c468f89

Browse files
committed
ike: don't log duplicate attributes
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: OISF#7923
1 parent 699586e commit c468f89

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

rust/src/ike/logger.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@ use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute};
2222
use crate::jsonbuilder::{JsonBuilder, JsonError};
2323
use num_traits::FromPrimitive;
2424
use std;
25+
use std::collections::HashSet;
2526
use std::convert::TryFrom;
2627

2728
const LOG_EXTENDED: u32 = 0x01;
2829

2930
fn add_attributes(transform: &Vec<SaAttribute>, js: &mut JsonBuilder) -> Result<(), JsonError> {
31+
let mut logged: HashSet<String> = HashSet::new();
32+
3033
for attribute in transform {
34+
let key = attribute.attribute_type.to_string();
35+
36+
if logged.contains(&key) {
37+
continue;
38+
}
39+
logged.insert(key.clone());
40+
3141
js.set_string(
32-
attribute.attribute_type.to_string().as_str(),
42+
&key,
3343
attribute.attribute_value.to_string().as_str(),
3444
)?;
3545

0 commit comments

Comments
 (0)