|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH] lib/vfscore: Fix error handling in opendir()
In case of errors, opendir() should set errno and return -1. If 'path' is not a
directory then opendir() should set errno to ENOTDIR.
Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
lib/vfscore/main.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index 925ce762..39013767 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -659,17 +659,33 @@ struct __dirstream
DIR *opendir(const char *path)
{
- DIR *dir = malloc(sizeof(*dir));
+ DIR *dir;
+ struct stat st;
- if (!dir)
- return ERR2PTR(-ENOMEM);
+ dir = malloc(sizeof(*dir));
+ if (!dir) {
+ errno = ENOMEM;
+ goto out_err;
+ }
dir->fd = open(path, O_RDONLY);
- if (dir->fd < 0) {
- free(dir);
- return NULL;
+ if (dir->fd < 0)
+ goto out_free_dir;
+
+ if (fstat(dir->fd, &st) < 0)
+ goto out_free_dir;
+
+ if (!S_ISDIR(st.st_mode)) {
+ errno = ENOTDIR;
+ goto out_free_dir;
}
+
return dir;
+
+out_free_dir:
+ free(dir);
+out_err:
+ return NULL;
}
DIR *fdopendir(int fd)
--
2.20.1
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |