naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
594167
From 6e0d847273e6ef6ee1011fb1c8b6689e64a94276 Mon Sep 17 00:00:00 2001
594167
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
594167
Date: Tue, 10 May 2022 09:05:43 +0200
594167
Subject: [PATCH] shared/json: fix another memleak in normalization
594167
594167
(cherry picked from commit 3b6ce05537cd3544a15073f920347cabd7a39450)
594167
Related: #2087652
594167
---
594167
 src/shared/json.c                         | 4 ++--
594167
 test/fuzz/fuzz-json/leak-normalize-object | 1 +
594167
 2 files changed, 3 insertions(+), 2 deletions(-)
594167
 create mode 100644 test/fuzz/fuzz-json/leak-normalize-object
594167
594167
diff --git a/src/shared/json.c b/src/shared/json.c
594167
index bb2363fd98..06ef556233 100644
594167
--- a/src/shared/json.c
594167
+++ b/src/shared/json.c
594167
@@ -4621,7 +4621,7 @@ int json_variant_sort(JsonVariant **v) {
594167
 
594167
 int json_variant_normalize(JsonVariant **v) {
594167
         _cleanup_free_ JsonVariant **a = NULL;
594167
-        JsonVariant *n = NULL;
594167
+        _cleanup_(json_variant_unrefp) JsonVariant *n = NULL;
594167
         size_t i, m;
594167
         int r;
594167
 
594167
@@ -4669,7 +4669,7 @@ int json_variant_normalize(JsonVariant **v) {
594167
                 goto finish;
594167
         }
594167
 
594167
-        JSON_VARIANT_REPLACE(*v, n);
594167
+        JSON_VARIANT_REPLACE(*v, TAKE_PTR(n));
594167
 
594167
         r = 1;
594167
 
594167
diff --git a/test/fuzz/fuzz-json/leak-normalize-object b/test/fuzz/fuzz-json/leak-normalize-object
594167
new file mode 100644
594167
index 0000000000..0a8caa426c
594167
--- /dev/null
594167
+++ b/test/fuzz/fuzz-json/leak-normalize-object
594167
@@ -0,0 +1 @@
594167
+[7,7,7,7,{"":7,"":7,"^t":7,"-":7},2777,7,7,7,3]
594167
\ No newline at end of file