]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: keep directory specifiers rootless
authordongshengyuan <545258830@qq.com>
Wed, 15 Jul 2026 05:22:04 +0000 (13:22 +0800)
committerdongshengyuan <545258830@qq.com>
Thu, 23 Jul 2026 06:33:16 +0000 (14:33 +0800)
%t and the other directory specifiers are parsed as normal paths.
They are prefixed by --root= later, so the specifier itself must stay
rootless.

Reproducer:
  tmp=$(mktemp -d /tmp/tmpfiles-root.XXXXXX)
  conf=$(mktemp /tmp/tmpfiles-conf.XXXXXX)
  printf 'd %%t/tmpfiles-repro 0755 - - -\n' >"$conf"
  systemd-tmpfiles --root="$tmp" --create --dry-run "$conf"

Before:
  Would create directory $tmp/$tmp/run/tmpfiles-repro

Follow-up for de61a04b188f81a85cdb5c64ddb4987dcd9d30d3.

src/tmpfiles/tmpfiles.c
test/units/TEST-22-TMPFILES.15.sh

index 82f6b8da2f2dc6d12defac89d94e99d35a4555a3..0e3244fcebe69388dec92b6c00e194409dad24f9 100644 (file)
@@ -322,16 +322,7 @@ static int specifier_directory(
         if (r < 0)
                 return r;
 
-        if (arg_root) {
-                _cleanup_free_ char *j = NULL;
-
-                j = path_join(arg_root, p);
-                if (!j)
-                        return -ENOMEM;
-
-                *ret = TAKE_PTR(j);
-        } else
-                *ret = TAKE_PTR(p);
+        *ret = TAKE_PTR(p);
 
         return 0;
 }
index 14c26b829582289e531e8a5297a7437a51bb5ad8..68c6c301bd6f5a9ef8e7d4ae2a3d90f07f8f9fc4 100755 (executable)
@@ -42,3 +42,15 @@ systemd-tmpfiles --create --root="$root" - <<EOF
 L     %h    - - - -
 EOF
 test "$(readlink "$dst")" = "$src"
+
+# Check that directory specifiers are not prefixed with --root twice.
+root='/tmp/L/3'
+rm -rf "$root"
+mkdir -p "$root"
+
+output="$(systemd-tmpfiles --create --dry-run --root="$root" - 2>&1 <<EOF
+d     %t/test    - - - -
+EOF
+)"
+[[ "$output" == *"Would create directory $root/run/test"* ]]
+[[ "$output" != *"$root$root"* ]]