]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: remove disabled compression entry before freeing
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 10 Jul 2026 14:38:22 +0000 (15:38 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 15 Jul 2026 20:11:09 +0000 (21:11 +0100)
compression_config_put() frees the COMPRESSION_NONE value when a later
algorithm is selected, but lefts the map entry pointing at it. Remove the
entry first so subsequent parsing, mangling, and teardown cannot access or
free stale memory.

Follow-up for c259c9e25329c93cb1b7363f89d917ffa5ce57c1

src/journal-remote/journal-compression-util.c
src/journal-remote/meson.build
src/journal-remote/test-journal-header-util.c

index 8e415878b958063b77d7f8da1036ca6f13ea6424..724725819198dd1321c64ca30ebf9528c1f27469 100644 (file)
@@ -41,7 +41,7 @@ static int compression_config_put(OrderedHashmap **configs, Compression c, int l
                                 free(ordered_hashmap_remove(*configs, INT_TO_PTR(cc->algorithm)));
         } else
                 /* otherwise, drop 'none' if stored. */
-                free(ordered_hashmap_get(*configs, INT_TO_PTR(COMPRESSION_NONE)));
+                free(ordered_hashmap_remove(*configs, INT_TO_PTR(COMPRESSION_NONE)));
 
         return 1;
 }
index 441a173eabbae1d6f82f61da362de4dca990be4d..b20ba1ec59d0d8888a6a86cdf4d5ba6c61aad939 100644 (file)
@@ -67,7 +67,7 @@ executables += [
         test_template + {
                 'sources' : files('test-journal-header-util.c'),
                 'conditions' : ['ENABLE_REMOTE', 'HAVE_LIBCURL'],
-                'import' : ['systemd-journal-upload'],
+                'import' : ['systemd-journal-remote', 'systemd-journal-upload'],
         },
         fuzz_template + {
                 'sources' : files('fuzz-journal-remote.c'),
index e88bb164ef7ce5248cb2c7b0426cfec5e45d1749..3dae9e8c9cc6a423f2191a15c24a21898dbd599a 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include "hashmap.h"
+#include "journal-compression-util.h"
 #include "journal-header-util.h"
 #include "tests.h"
 
@@ -18,4 +19,30 @@ TEST(header_put) {
         ASSERT_ERROR(header_put(&headers, "", "Value"), EINVAL);
 }
 
+TEST(compression_none_then_algorithm) {
+        _cleanup_ordered_hashmap_free_ OrderedHashmap *configs = NULL;
+        Compression compression = COMPRESSION_NONE;
+
+        for (Compression c = 1; c < _COMPRESSION_MAX; c++)
+                if (compression_supported(c)) {
+                        compression = c;
+                        break;
+                }
+
+        if (compression == COMPRESSION_NONE)
+                return (void) log_tests_skipped("No compression algorithm supported");
+
+        ASSERT_OK_POSITIVE(config_parse_compression(
+                        "test", "test.conf", 1, "Upload", 1, "Compression", false, "no", &configs, NULL));
+        ASSERT_TRUE(ordered_hashmap_contains(configs, INT_TO_PTR(COMPRESSION_NONE)));
+
+        ASSERT_OK_POSITIVE(config_parse_compression(
+                        "test", "test.conf", 2, "Upload", 1, "Compression", false,
+                        compression_to_string(compression), &configs, NULL));
+        ASSERT_FALSE(ordered_hashmap_contains(configs, INT_TO_PTR(COMPRESSION_NONE)));
+        ASSERT_NOT_NULL(ordered_hashmap_get(configs, INT_TO_PTR(compression)));
+
+        ASSERT_OK(compression_configs_mangle(&configs));
+}
+
 DEFINE_TEST_MAIN(LOG_DEBUG);