summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-08-31 18:05:01 +0200
committerThomas Weißschuh <linux@weissschuh.net>2026-09-14 00:18:54 +0200
commitf19ae28f1f050b7d6551412a04281955cc4103e5 (patch)
tree565866b681b917b1fb20583f3dc9c29d1cdc733a /tools/include
parent9c47af906bc655c8f45aaf1f156656239c2c5073 (diff)
tools/nolibc: validate directory with O_DIRECTORY in opendir()
Switch to O_DIRECTORY to validate that the opened file is a directory. ALso remove the call to fdopendir() in opendir() to avoid a double check of 'fd'. This will also make it easier to add a similar check for fdopendir(). 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-3-8cf0e79c4e6f@weissschuh.net
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/dirent.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index 4e02ef25e72d..c7372c935e0d 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -42,10 +42,11 @@ DIR *opendir(const char *name)
{
int fd;
- fd = open(name, O_RDONLY);
+ fd = open(name, O_RDONLY | O_DIRECTORY);
if (fd == -1)
return NULL;
- return fdopendir(fd);
+
+ return (DIR *)(intptr_t)~fd;
}
static __attribute__((unused))