From 7ec4376eb0d4d8b9f3178c2b8867376ae9ef05f8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 21 Nov 2026 10:11:07 +0100 Subject: [PATCH] tmpfiles: take 8 and 9 as hex digits in an \x escape An f or w entry with \x39 in the argument writes the byte 3 followed by a 9, where it should write a 9: f /tmp/file - - - - \x39 write_hex() only takes the digits 0 to 7, as for an octal escape. Take all hex digits. Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 2 ++ src/tmpfiles.c | 5 ++--- test/tmpfiles-arg.sh | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index b5315a30..588b21d6 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -315,6 +315,8 @@ All relevant changes are documented in this file. - Fix age `0` in a tmpfiles entry, it was read as no age. As in tmpfiles.d(5), `tmpfiles --clean` now empties the directory of such an entry +- Fix `\x` escapes with the digits 8 or 9 in the argument of a tmpfiles + entry, `\x39` was written as the byte 3 and a `9` - 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/src/tmpfiles.c b/src/tmpfiles.c index 67ae8df3..da405a99 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -23,6 +23,7 @@ #include "config.h" /* Generated by configure script */ +#include #include #include #include @@ -190,9 +191,7 @@ static char *write_hex(FILE *fp, char *p) for (i = 0; p[i] && len < 2; i++) { char c = p[i]; - if ((c >= '0' && c <= '7') || - (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F')) + if (isxdigit((unsigned char)c)) num[len++] = c; else break; diff --git a/test/tmpfiles-arg.sh b/test/tmpfiles-arg.sh index 6d8272c7..20eabd85 100755 --- a/test/tmpfiles-arg.sh +++ b/test/tmpfiles-arg.sh @@ -64,3 +64,11 @@ CONF run "/libexec/finit/tmpfiles --create $CONF" assert "First match" "$(texec cat $DIR/w1 | tr '\n' ' ')" = "one two" assert "Second match" "$(texec cat $DIR/w2 | tr '\n' ' ')" = "one two" + +sep +say 'Escapes in the argument' +run "cat > $CONF" <<'CONF' +f /tmp/arg/hex - - - - \x39\x41\x4a\x6b +CONF +run "/libexec/finit/tmpfiles --create $CONF" +assert "All hex digits" "$(texec cat $DIR/hex)" = "9AJk"