52 lines
1.9 KiB
Diff
52 lines
1.9 KiB
Diff
|
|
From 7a2349072e165c27ed0655934b05530c19d23779 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||
|
|
Date: Thu, 15 Feb 2024 07:01:17 +0900
|
||
|
|
Subject: [PATCH] fs-util: readlinkat() supports an empty string
|
||
|
|
|
||
|
|
From readlinkat(2):
|
||
|
|
Since Linux 2.6.39, pathname can be an empty string, in which case the
|
||
|
|
call operates on the symbolic link referred to by dirfd (which should
|
||
|
|
have been obtained using open(2) with the O_PATH and O_NOFOLLOW flags).
|
||
|
|
|
||
|
|
(cherry picked from commit e4c094c05543410ba05a16f757d1e11652f4f6bd)
|
||
|
|
(cherry picked from commit 30142e781d7afcfa93185d2543f59e9cf90dc882)
|
||
|
|
|
||
|
|
Conflict:due to the absence of mkdtemp_open, the test case related content will not be included
|
||
|
|
Reference:https://github.com/systemd/systemd-stable/commit/7a2349072e165c27ed0655934b05530c19d23779
|
||
|
|
---
|
||
|
|
src/basic/fs-util.c | 9 +++++++--
|
||
|
|
1 file changed, 7 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
|
||
|
|
index 8f0834f..287fc29 100644
|
||
|
|
--- a/src/basic/fs-util.c
|
||
|
|
+++ b/src/basic/fs-util.c
|
||
|
|
@@ -137,9 +137,14 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
|
||
|
|
int readlinkat_malloc(int fd, const char *p, char **ret) {
|
||
|
|
size_t l = PATH_MAX;
|
||
|
|
|
||
|
|
- assert(p);
|
||
|
|
assert(ret);
|
||
|
|
|
||
|
|
+ assert(fd >= 0 || fd == AT_FDCWD);
|
||
|
|
+
|
||
|
|
+ if (fd < 0 && isempty(p))
|
||
|
|
+ return -EISDIR; /* In this case, the fd points to the current working directory, and is
|
||
|
|
+ * definitely not a symlink. Let's return earlier. */
|
||
|
|
+
|
||
|
|
for (;;) {
|
||
|
|
_cleanup_free_ char *c = NULL;
|
||
|
|
ssize_t n;
|
||
|
|
@@ -148,7 +153,7 @@ int readlinkat_malloc(int fd, const char *p, char **ret) {
|
||
|
|
if (!c)
|
||
|
|
return -ENOMEM;
|
||
|
|
|
||
|
|
- n = readlinkat(fd, p, c, l);
|
||
|
|
+ n = readlinkat(fd, strempty(p), c, l);
|
||
|
|
if (n < 0)
|
||
|
|
return -errno;
|
||
|
|
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|