summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-08-31 18:04:59 +0200
committerThomas Weißschuh <linux@weissschuh.net>2026-09-14 00:19:57 +0200
commitf90242f39f32c6d708c33af504bdc80a683f0da4 (patch)
treec5c62e3e89743bc89f8f60ee313c3f19de8560c7 /tools/include
parentf19ae28f1f050b7d6551412a04281955cc4103e5 (diff)
downloadlinux-next-f90242f39f32c6d708c33af504bdc80a683f0da4.tar.gz
linux-next-f90242f39f32c6d708c33af504bdc80a683f0da4.zip
tools/nolibc: verify that a directory is opened
If a non-directory is opened, ENODIR should be returned from opendir()/fdopendir() right away and not only during readdir_r(). Validate the type of opened file during open. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Reviewed-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260831-nolibc-fdopendir-enotdir-v1-1-8cf0e79c4e6f@weissschuh.net
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/dirent.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index c7372c935e0d..2dbf4052b85a 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -30,10 +30,23 @@ typedef struct {
static __attribute__((unused))
DIR *fdopendir(int fd)
{
+ struct stat buf;
+ int ret;
+
if (fd < 0) {
SET_ERRNO(EBADF);
return NULL;
}
+
+ ret = fstat(fd, &buf);
+ if (ret < 0)
+ return NULL;
+
+ if (!S_ISDIR(buf.st_mode)) {
+ SET_ERRNO(ENOTDIR);
+ return NULL;
+ }
+
return (DIR *)(intptr_t)~fd;
}