systemd/0441-chase-check-the-result-is-a-directory-or-regular-fil.patch
Jan Macku ed1b047fb9 systemd-257-14
Resolves: RHEL-108006,RHEL-108242,RHEL-108251,RHEL-108257,RHEL-109552
2025-09-15 14:30:09 +02:00

59 lines
2.1 KiB
Diff

From d81f351e334d852978277ac716043ad957ec2a85 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 29 Jul 2025 03:25:17 +0900
Subject: [PATCH] chase: check the result is a directory or regular file only
when the resolved path exists
Otherwise, if it is called with CHASE_NONEXISTENT, when we call
stat_verify_directory()/_regular() the struct stat is for one of the
parent directory, rather than for the result path.
With this change, we can safely specify CHASE_MUST_BE_DIRECTORY/REGULAR
with CHASE_NONEXISTENT.
More importantly, chaseat() internally sets CHASE_MUST_BE_DIRECTORY when
the input path ends with "/", "/,", "/..". Hence, without this change,
we cannot specify CHASE_NONEXISTENT safely.
Follow-up for 90b9f7a07e6f57825f416f6ce2db0a9f2086754b.
(cherry picked from commit 1cabb6905b98ecc11bfb1fd8305c8f5c089e5c32)
Resolves: RHEL-108006
---
src/basic/chase.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/basic/chase.c b/src/basic/chase.c
index e5a6fb1587..3db1ea7e0e 100644
--- a/src/basic/chase.c
+++ b/src/basic/chase.c
@@ -485,16 +485,18 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
close_and_replace(fd, child);
}
- if (FLAGS_SET(flags, CHASE_MUST_BE_DIRECTORY)) {
- r = stat_verify_directory(&st);
- if (r < 0)
- return r;
- }
+ if (exists) {
+ if (FLAGS_SET(flags, CHASE_MUST_BE_DIRECTORY)) {
+ r = stat_verify_directory(&st);
+ if (r < 0)
+ return r;
+ }
- if (FLAGS_SET(flags, CHASE_MUST_BE_REGULAR)) {
- r = stat_verify_regular(&st);
- if (r < 0)
- return r;
+ if (FLAGS_SET(flags, CHASE_MUST_BE_REGULAR)) {
+ r = stat_verify_regular(&st);
+ if (r < 0)
+ return r;
+ }
}
if (ret_path) {