From: Frantisek Sumsal Date: Mon, 12 Feb 2024 17:32:03 +0000 (+0100) Subject: core: escape spaces when serializing as well X-Git-Tag: v256-rc1~884 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b1aa0e19a6df603336894604a85df74204d04f9;p=thirdparty%2Fsystemd.git core: escape spaces when serializing as well Otherwise they might get stripped when reading the serialized data back. Resolves: #31214 --- diff --git a/src/shared/serialize.c b/src/shared/serialize.c index 7099f67f92c..483cbc7419b 100644 --- a/src/shared/serialize.c +++ b/src/shared/serialize.c @@ -46,7 +46,7 @@ int serialize_item_escaped(FILE *f, const char *key, const char *value) { if (!value) return 0; - c = cescape(value); + c = xescape(value, " "); if (!c) return log_oom(); diff --git a/test/units/testsuite-07.exec-context.sh b/test/units/testsuite-07.exec-context.sh index dd63163008e..e1e4367cc63 100755 --- a/test/units/testsuite-07.exec-context.sh +++ b/test/units/testsuite-07.exec-context.sh @@ -338,6 +338,39 @@ if [[ ! -v ASAN_OPTIONS ]] && systemctl --version | grep "+BPF_FRAMEWORK" && ker (! systemd-run --wait --pipe -p RestrictFileSystems="~proc devtmpfs sysfs" ls /sys) fi +# Make sure we properly (de)serialize various string arrays, including whitespaces +# See: https://github.com/systemd/systemd/issues/31214 +systemd-run --wait --pipe -p Environment="FOO='bar4 '" \ + bash -xec '[[ $FOO == "bar4 " ]]' +systemd-run --wait --pipe -p Environment="FOO='bar4 ' BAR='\n\n'" \ + bash -xec "[[ \$FOO == 'bar4 ' && \$BAR == $'\n\n' ]]" +systemd-run --wait --pipe -p Environment='FOO="bar4 \\ "' -p Environment="BAR='\n\t'" \ + bash -xec "[[ \$FOO == 'bar4 \\ ' && \$BAR == $'\n\t' ]]" +TEST_ENV_FILE="/tmp/test-env-file-$RANDOM- " +cat >"$TEST_ENV_FILE" <