From 4bec72fcf2b7566cce665060b7dcc69d6e15d846 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 21 Nov 2026 18:59:02 +0100 Subject: [PATCH] tmpfiles: skip an entry with a relative path An entry with a path like tmp/file was run on the directory tmpfiles happened to be started in. tmpfiles.d(5) only has absolute paths, and systemd skips such a line. Do the same, with a warning. Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 3 +++ doc/tmpfiles-todo.md | 2 -- src/tmpfiles.c | 7 ++++++- test/tmpfiles-arg.sh | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index db02880d..af5468ec 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -348,6 +348,9 @@ All relevant changes are documented in this file. entry in Finit's own `etc.conf`. A file was copied over an existing one. As in tmpfiles.d(5), nothing that exists is now overwritten, and links are copied as links +- Fix tmpfiles entries with a relative path, they were run on whatever + directory `tmpfiles` was started in. As in tmpfiles.d(5), such an + entry is now skipped with a warning - Fix logins refused after boot on a system with systemd's tmpfiles.d files installed. They create `/run/nologin` at boot, and on systemd it is removed by systemd-user-sessions. Finit now removes it when leaving diff --git a/doc/tmpfiles-todo.md b/doc/tmpfiles-todo.md index 0f08f2a7..9600414b 100644 --- a/doc/tmpfiles-todo.md +++ b/doc/tmpfiles-todo.md @@ -30,5 +30,3 @@ Missing options: `--root`, `--replace`, and `--purge`. first and Finit runs both, so the last one wins. Today that is the one in `/etc`, which is what an admin expects. Sorted by name it would be the one in `/usr/lib`. Both changes have to go in together -* A relative path is taken as it is, tmpfiles.d(5) only has absolute - ones diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 855d24aa..dce4ceb2 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -1628,7 +1628,7 @@ static void replace_kind(const char *path, mode_t fmt) struct stat st; /* Nothing is removed by a path that may lead somewhere else */ - if (path[0] != '/' || strstr(path, "/./") || strstr(path, "/../")) + if (strstr(path, "/./") || strstr(path, "/../")) return; for (size_t len = strlen(copy); len > 1 && copy[len - 1] == '/'; len--) @@ -1784,6 +1784,11 @@ static void tmpfiles(char *line) } path = ptr; } + if (path[0] != '/') { + if (!quiet) + warnx("Path is not absolute, skipping %s", path); + return; + } if (excluded(path)) return; if (collect) { diff --git a/test/tmpfiles-arg.sh b/test/tmpfiles-arg.sh index e6bb738d..95003cbb 100755 --- a/test/tmpfiles-arg.sh +++ b/test/tmpfiles-arg.sh @@ -95,13 +95,15 @@ f '/tmp/arg/single quote' - - - - single f /tmp/arg/mid"dle sp"ace - - - - middle f /tmp/arg/esc\x41\sped - - - - "kept as is" f "/tmp/arg/open - - - - quote +f tmp/arg/relative - - - - path CONF -run "/libexec/finit/tmpfiles --create $CONF" +run "cd /; /libexec/finit/tmpfiles --create $CONF" assert "Double quotes" "$(texec cat "$DIR/with space")" = "double" assert "Single quotes" "$(texec cat "$DIR/single quote")" = "single" assert "Quotes in path" "$(texec cat "$DIR/middle space")" = "middle" assert "Escapes in path" "$(texec cat "$DIR/escA ped")" = '"kept as is"' assert "Skipped with a quote left open" "$(texec sh -c "ls $DIR | grep -c open")" = "0" +assert "Skipped when not absolute" "$(texec sh -c "ls $DIR | grep -c relative")" = "0" sep say 'With ~ the argument is Base64'