]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/dns: Ensure JSON object doesn't get leaked
authorJeff Lucovsky <jeff@lucovsky.org>
Thu, 16 Dec 2021 14:32:52 +0000 (09:32 -0500)
committerVictor Julien <vjulien@oisf.net>
Sun, 19 Dec 2021 14:18:30 +0000 (15:18 +0100)
Ensure js_answers isn't leaked when detailed logging is not in use. This
commit changes how js_answers allocation is performed. Previously, it
was allocated regardless of whether detailed logging was enabled. Now,
it's only allocated if detailed logging is enabled.

Ticket: #4901

rust/src/dns/log.rs

index cd8ef9758ce516772e9646ae2a2a3444bf26e188..8225508fce0d8ea86d3ec89af2a83b5eba2cc741 100644 (file)
@@ -478,7 +478,7 @@ fn dns_log_json_answer(response: &DNSResponse, flags: u64) -> Json
     js.set_string("rcode", &dns_rcode_string(header.flags));
 
     if response.answers.len() > 0 {
-        let js_answers = Json::array();
+        let js_answers = if flags & LOG_FORMAT_DETAILED != 0 { Some(Json::array()) } else { None };
 
         // For grouped answers we use a HashMap keyed by the rrtype.
         let mut answer_types = HashMap::new();
@@ -526,12 +526,13 @@ fn dns_log_json_answer(response: &DNSResponse, flags: u64) -> Json
                 }
             }
 
-            if flags & LOG_FORMAT_DETAILED != 0 {
+            if let Some(js_answers) = &js_answers {
                 js_answers.array_append(dns_log_json_answer_detail(answer));
             }
         }
 
-        if flags & LOG_FORMAT_DETAILED != 0 {
+
+        if let Some(js_answers) = js_answers {
             js.set("answers", js_answers);
         }