summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-21 18:07:06 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-10 15:01:29 +0100
commite1e32516f98a1f39ce763545de9a8664526d0b8a (patch)
tree7d98ca7a601f0de81d1f32f815b2c1d3bec9fd65
parent214ea3a26e9cc5dda8530a45a71b052e75a250a4 (diff)
downloadsystemd-e1e32516f98a1f39ce763545de9a8664526d0b8a.tar.gz
stat-util: specify O_DIRECTORY when reopening dir in dir_is_empty_at()
That way we can fail earlier if the specified fd is not actually a directory. (Also, it's not exactly according to standards to open things without either O_RDONLY/O_RDWR...) (cherry picked from commit b9d06522631a22d242374dc44a74c3b6459e3cb3)
-rw-r--r--src/basic/stat-util.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c
index 72a7e4a48b..56f7652cec 100644
--- a/src/basic/stat-util.c
+++ b/src/basic/stat-util.c
@@ -79,7 +79,7 @@ int dir_is_empty_at(int dir_fd, const char *path) {
} else {
/* Note that DUPing is not enough, as the internal pointer
* would still be shared and moved by FOREACH_DIRENT. */
- fd = fd_reopen(dir_fd, O_CLOEXEC);
+ fd = fd_reopen(dir_fd, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
if (fd < 0)
return fd;
}