From 13f6ec7ce7c89538b359b380d6b750da95cae31a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 18 Sep 2024 05:00:21 +0900 Subject: [PATCH] test: quote paths to executables Fixes #34459. --- src/test/test-compress.c | 4 ++-- src/udev/test-udev-spawn.c | 3 ++- test/test-compare-versions.sh | 44 +++++++++++++++++------------------ test/test-fstab-generator.sh | 4 ++-- test/test-sysusers.sh.in | 36 ++++++++++++++-------------- 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/test/test-compress.c b/src/test/test-compress.c index 868b862dc7a..86311c6217e 100644 --- a/src/test/test-compress.c +++ b/src/test/test-compress.c @@ -197,7 +197,7 @@ _unused_ static void test_compress_stream(const char *compression, ASSERT_OK(compress(src, dst, -1, &uncompressed_size)); if (cat) { - assert_se(asprintf(&cmd, "%s %s | diff %s -", cat, pattern, srcfile) > 0); + assert_se(asprintf(&cmd, "%s %s | diff '%s' -", cat, pattern, srcfile) > 0); assert_se(system(cmd) == 0); } @@ -212,7 +212,7 @@ _unused_ static void test_compress_stream(const char *compression, r = decompress(dst, dst2, st.st_size); assert_se(r == 0); - assert_se(asprintf(&cmd2, "diff %s %s", srcfile, pattern2) > 0); + assert_se(asprintf(&cmd2, "diff '%s' %s", srcfile, pattern2) > 0); assert_se(system(cmd2) == 0); log_debug("/* test faulty decompression */"); diff --git a/src/udev/test-udev-spawn.c b/src/udev/test-udev-spawn.c index 7cbccf32a60..a6079e3c613 100644 --- a/src/udev/test-udev-spawn.c +++ b/src/udev/test-udev-spawn.c @@ -52,7 +52,8 @@ static void test_event_spawn_self(const char *self, const char *arg, bool with_p log_debug("/* %s(%s, %s) */", __func__, arg, yes_no(with_pidfd)); - assert_se(cmd = strjoin(self, " ", arg)); + /* 'self' may contain spaces, hence needs to be quoted. */ + assert_se(cmd = strjoin("'", self, "' ", arg)); test_event_spawn_core(with_pidfd, cmd, result_buf, BUF_SIZE); diff --git a/test/test-compare-versions.sh b/test/test-compare-versions.sh index c40208be608..e9acd9cbeee 100755 --- a/test/test-compare-versions.sh +++ b/test/test-compare-versions.sh @@ -4,32 +4,32 @@ set -e ANALYZE="${1:-systemd-analyze}" -$ANALYZE compare-versions 1 lt 2 -$ANALYZE compare-versions 1 '<' 2 -$ANALYZE compare-versions 1 le 2 -$ANALYZE compare-versions 1 '<=' 2 -$ANALYZE compare-versions 1 ne 2 -$ANALYZE compare-versions 1 '!=' 2 -( ! $ANALYZE compare-versions 1 ge 2 ) -( ! $ANALYZE compare-versions 1 '>=' 2 ) -( ! $ANALYZE compare-versions 1 eq 2 ) -( ! $ANALYZE compare-versions 1 '==' 2 ) -( ! $ANALYZE compare-versions 1 gt 2 ) -( ! $ANALYZE compare-versions 1 '>' 2 ) +"$ANALYZE" compare-versions 1 lt 2 +"$ANALYZE" compare-versions 1 '<' 2 +"$ANALYZE" compare-versions 1 le 2 +"$ANALYZE" compare-versions 1 '<=' 2 +"$ANALYZE" compare-versions 1 ne 2 +"$ANALYZE" compare-versions 1 '!=' 2 +( ! "$ANALYZE" compare-versions 1 ge 2 ) +( ! "$ANALYZE" compare-versions 1 '>=' 2 ) +( ! "$ANALYZE" compare-versions 1 eq 2 ) +( ! "$ANALYZE" compare-versions 1 '==' 2 ) +( ! "$ANALYZE" compare-versions 1 gt 2 ) +( ! "$ANALYZE" compare-versions 1 '>' 2 ) -test "$($ANALYZE compare-versions 1 2)" = '1 < 2' -test "$($ANALYZE compare-versions 2 2)" = '2 == 2' -test "$($ANALYZE compare-versions 2 1)" = '2 > 1' -test "$($ANALYZE compare-versions '' '')" = "'' == ''" +test "$("$ANALYZE" compare-versions 1 2)" = '1 < 2' +test "$("$ANALYZE" compare-versions 2 2)" = '2 == 2' +test "$("$ANALYZE" compare-versions 2 1)" = '2 > 1' +test "$("$ANALYZE" compare-versions '' '')" = "'' == ''" set +e -$ANALYZE compare-versions 1 2; ret1=$? -$ANALYZE compare-versions 2 2; ret2=$? -$ANALYZE compare-versions 2 1; ret3=$? +"$ANALYZE" compare-versions 1 2; ret1=$? +"$ANALYZE" compare-versions 2 2; ret2=$? +"$ANALYZE" compare-versions 2 1; ret3=$? set -e -test $ret1 == 12 -test $ret2 == 0 -test $ret3 == 11 +test "$ret1" == 12 +test "$ret2" == 0 +test "$ret3" == 11 diff --git a/test/test-fstab-generator.sh b/test/test-fstab-generator.sh index af8fa7c226d..24a2533f16b 100755 --- a/test/test-fstab-generator.sh +++ b/test/test-fstab-generator.sh @@ -44,9 +44,9 @@ test_one() ( fi if [[ "${input##*/}" =~ \.fstab\.input ]]; then - SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD="$initrd" SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=yes root=fstab" SYSTEMD_FSTAB="$input" SYSTEMD_SYSROOT_FSTAB="/dev/null" $generator "$out" "$out" "$out" + SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD="$initrd" SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=yes root=fstab" SYSTEMD_FSTAB="$input" SYSTEMD_SYSROOT_FSTAB="/dev/null" "$generator" "$out" "$out" "$out" else - SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD="$initrd" SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=no $(cat "$input")" $generator "$out" "$out" "$out" + SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD="$initrd" SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=no $(cat "$input")" "$generator" "$out" "$out" "$out" fi # The option x-systemd.growfs creates symlink to system's systemd-growfs@.service in .mount.wants directory. diff --git a/test/test-sysusers.sh.in b/test/test-sysusers.sh.in index 9af253f6c72..fdeae2c8981 100755 --- a/test/test-sysusers.sh.in +++ b/test/test-sysusers.sh.in @@ -53,7 +53,7 @@ for f in $(find "$SOURCE"/test-*.input | sort -V); do echo "*** Running $f" prepare_testdir "${f%.input}" cp "$f" "$TESTDIR/usr/lib/sysusers.d/test.conf" - $SYSUSERS --root="$TESTDIR" + "$SYSUSERS" --root="$TESTDIR" compare "${f%.*}" "" done @@ -62,7 +62,7 @@ for f in $(find "$SOURCE"/test-*.input | sort -V); do echo "*** Running $f on stdin" prepare_testdir "${f%.input}" touch "$TESTDIR/etc/sysusers.d/test.conf" - $SYSUSERS --root="$TESTDIR" - <"$f" + "$SYSUSERS" --root="$TESTDIR" - <"$f" compare "${f%.*}" "on stdin" done @@ -72,9 +72,9 @@ for f in $(find "$SOURCE"/test-*.input | sort -V); do prepare_testdir "${f%.input}" touch "$TESTDIR/etc/sysusers.d/test.conf" # this overrides test.conf which is masked on disk - $SYSUSERS --root="$TESTDIR" --replace=/etc/sysusers.d/test.conf - <"$f" + "$SYSUSERS" --root="$TESTDIR" --replace=/etc/sysusers.d/test.conf - <"$f" # this should be ignored - $SYSUSERS --root="$TESTDIR" --replace=/usr/lib/sysusers.d/test.conf - <"$SOURCE/test-1.input" + "$SYSUSERS" --root="$TESTDIR" --replace=/usr/lib/sysusers.d/test.conf - <"$SOURCE/test-1.input" compare "${f%.*}" "on stdin with --replace" done @@ -84,9 +84,9 @@ echo "*** Testing --inline" prepare_testdir "$SOURCE/inline" # copy a random file to make sure it is ignored cp "$f" "$TESTDIR/etc/sysusers.d/confuse.conf" -$SYSUSERS --root="$TESTDIR" --inline \ - "u u1 222 - - /bin/zsh" \ - "g g1 111" +"$SYSUSERS" --root="$TESTDIR" --inline \ + "u u1 222 - - /bin/zsh" \ + "g g1 111" compare "$SOURCE/inline" "(--inline)" @@ -95,19 +95,19 @@ echo "*** Testing --inline with --replace" prepare_testdir "$SOURCE/inline" # copy a random file to make sure it is ignored cp "$f" "$TESTDIR/etc/sysusers.d/confuse.conf" -$SYSUSERS --root="$TESTDIR" \ - --inline \ - --replace=/etc/sysusers.d/confuse.conf \ - "u u1 222 - - /bin/zsh" \ - "g g1 111" +"$SYSUSERS" --root="$TESTDIR" \ + --inline \ + --replace=/etc/sysusers.d/confuse.conf \ + "u u1 222 - - /bin/zsh" \ + "g g1 111" compare "$SOURCE/inline" "(--inline --replace=…)" echo "*** Testing --inline with no /etc" rm -rf "${TESTDIR:?}/etc" -$SYSUSERS --root="$TESTDIR" --inline \ - "u u1 222 - - /bin/zsh" \ - "g g1 111" +"$SYSUSERS" --root="$TESTDIR" --inline \ + "u u1 222 - - /bin/zsh" \ + "g g1 111" compare "$SOURCE/inline" "(--inline)" @@ -136,7 +136,7 @@ for f in $(find "$SOURCE"/test-*.input | sort -V); do echo "*** Running $f (with login.defs)" prepare_testdir "${f%.input}" cp "$f" "$TESTDIR/usr/lib/sysusers.d/test.conf" - $SYSUSERS --root="$TESTDIR" + "$SYSUSERS" --root="$TESTDIR" # shellcheck disable=SC2050 [ @ENABLE_COMPAT_MUTABLE_UID_BOUNDARIES@ = 1 ] && bound=555 || bound=$system_guid_max @@ -152,7 +152,7 @@ for f in $(find "$SOURCE"/test-*.input | sort -V); do echo "*** Running $f (with login.defs symlinked)" prepare_testdir "${f%.input}" cp "$f" "$TESTDIR/usr/lib/sysusers.d/test.conf" - $SYSUSERS --root="$TESTDIR" + "$SYSUSERS" --root="$TESTDIR" # shellcheck disable=SC2050 [ @ENABLE_COMPAT_MUTABLE_UID_BOUNDARIES@ = 1 ] && bound=555 || bound=$system_guid_max @@ -166,7 +166,7 @@ for f in $(find "$SOURCE"/unhappy-*.input | sort -V); do echo "*** Running test $f" prepare_testdir "${f%.input}" cp "$f" "$TESTDIR/usr/lib/sysusers.d/test.conf" - SYSTEMD_LOG_LEVEL=info $SYSUSERS --root="$TESTDIR" 2>&1 | tail -n1 | sed -r 's/^[^:]+:[^:]+://' >"$TESTDIR/err" + SYSTEMD_LOG_LEVEL=info "$SYSUSERS" --root="$TESTDIR" 2>&1 | tail -n1 | sed -r 's/^[^:]+:[^:]+://' >"$TESTDIR/err" if ! diff -u "$TESTDIR/err" "${f%.*}.expected-err"; then echo >&2 "**** Unexpected error output for $f" cat >&2 "$TESTDIR/err"