teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0113-shared-json-fix-another-memleak-in-normalization.patch

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