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 c259c9e253
This commit is contained in:
Luca Boccassi
2026-07-15 21:11:09 +01:00
parent afff448cf4
commit 16c6758eb4
3 changed files with 29 additions and 2 deletions
@@ -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;
}
+1 -1
View 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'),
@@ -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);