From 0fbffb3b74d6cbbc2062bb5a181279762d276ad6 Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Sun, 19 Dec 2021 13:08:59 -0500 Subject: [PATCH] output/json: Eliminate dangling XFF reference This commit eliminates a dangling reference caused by the use of json_object_set. This function adds a reference to the final parameter -- in this case the object returned by json_string() whereas json_object_set_new doesn't add the additional reference to the final parameter. --- src/output-json-alert.c | 4 ++-- src/output-json-file.c | 4 ++-- src/output-json-http.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/output-json-alert.c b/src/output-json-alert.c index 175bf4f4cd..54398374b2 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -585,9 +585,9 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p) } else if (xff_cfg->flags & XFF_OVERWRITE) { if (p->flowflags & FLOW_PKT_TOCLIENT) { - json_object_set(js, "dest_ip", json_string(buffer)); + json_object_set_new(js, "dest_ip", json_string(buffer)); } else { - json_object_set(js, "src_ip", json_string(buffer)); + json_object_set_new(js, "src_ip", json_string(buffer)); } } } diff --git a/src/output-json-file.c b/src/output-json-file.c index 17134a477a..3ff42454cb 100644 --- a/src/output-json-file.c +++ b/src/output-json-file.c @@ -234,9 +234,9 @@ json_t *JsonBuildFileInfoRecord(const Packet *p, const File *ff, } else if (xff_cfg->flags & XFF_OVERWRITE) { if (p->flowflags & FLOW_PKT_TOCLIENT) { - json_object_set(js, "dest_ip", json_string(buffer)); + json_object_set_new(js, "dest_ip", json_string(buffer)); } else { - json_object_set(js, "src_ip", json_string(buffer)); + json_object_set_new(js, "src_ip", json_string(buffer)); } } } diff --git a/src/output-json-http.c b/src/output-json-http.c index 2e3a62ecf2..a95cbbe46d 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -545,9 +545,9 @@ static int JsonHttpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl } else if (xff_cfg->flags & XFF_OVERWRITE) { if (p->flowflags & FLOW_PKT_TOCLIENT) { - json_object_set(js, "dest_ip", json_string(buffer)); + json_object_set_new(js, "dest_ip", json_string(buffer)); } else { - json_object_set(js, "src_ip", json_string(buffer)); + json_object_set_new(js, "src_ip", json_string(buffer)); } } } -- 2.47.2