From: Luca Boccassi Date: Fri, 10 Jul 2026 14:38:22 +0000 (+0100) Subject: journal-remote: remove disabled compression entry before freeing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16c6758eb4128d199797ad417dd6a6580e53a61a;p=thirdparty%2Fsystemd.git journal-remote: remove disabled compression entry before freeing 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 --- diff --git a/src/journal-remote/journal-compression-util.c b/src/journal-remote/journal-compression-util.c index 8e415878b95..72472581919 100644 --- a/src/journal-remote/journal-compression-util.c +++ b/src/journal-remote/journal-compression-util.c @@ -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; } diff --git a/src/journal-remote/meson.build b/src/journal-remote/meson.build index 441a173eabb..b20ba1ec59d 100644 --- a/src/journal-remote/meson.build +++ b/src/journal-remote/meson.build @@ -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'), diff --git a/src/journal-remote/test-journal-header-util.c b/src/journal-remote/test-journal-header-util.c index e88bb164ef7..3dae9e8c9cc 100644 --- a/src/journal-remote/test-journal-header-util.c +++ b/src/journal-remote/test-journal-header-util.c @@ -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);