From: Lennart Poettering Date: Fri, 22 Oct 2021 22:31:33 +0000 (+0200) Subject: stat-util: make sure dir_is_empty_at() does something useful in all cases X-Git-Tag: v250-rc1~426^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d96f21eec2c0d6cce25ca6782f76f053b2ed5cc9;p=thirdparty%2Fsystemd.git stat-util: make sure dir_is_empty_at() does something useful in all cases --- diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 900f06ad1c7..77e728bcab5 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -80,9 +80,15 @@ int dir_is_empty_at(int dir_fd, const char *path) { ssize_t n; if (path) { + assert(dir_fd >= 0 || dir_fd == AT_FDCWD); + fd = openat(dir_fd, path, O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (fd < 0) return -errno; + } else if (dir_fd == AT_FDCWD) { + fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); + if (fd < 0) + return -errno; } else { /* Note that DUPing is not enough, as the internal pointer would still be shared and moved * getedents64(). */