[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Minios-devel] [UNIKRAFT PATCH] lib/vfscore: Fix error handling in opendir()
- To: minios-devel@xxxxxxxxxxxxx
- From: Costin Lupu <costin.lupu@xxxxxxxxx>
- Date: Thu, 12 Sep 2019 11:47:45 +0300
- Cc: felipe.huici@xxxxxxxxx, vlad_andrei.badoiu@xxxxxxxxxxxxxxx
- Delivery-date: Thu, 12 Sep 2019 08:47:54 +0000
- Ironport-phdr: 9a23:adeTOBDd1bHpRSPM3smgUyQJP3N1i/DPJgcQr6AfoPdwSPX5rsbcNUDSrc9gkEXOFd2Cra4d0KyO7uu4BCRAuc/H7ClYNsQUFlcssoY/p0QYGsmLCEn2frbBThcRO4B8bmJj5GyxKkNPGczzNBX4q3y26iMOSF2kbVImbuv6FZTPgMupyuu854PcYxlShDq6fLh+MAi6oR/eu8ULj4ZuMLo9xxvGrndUe+ld2GdkKU6Okxrm6cq84YBv/z5Mt/498sJLTLn3cbk/QbFEFjotLno75NfstRnNTAuP4mUTX2ALmRdWAAbL8Q/3UI7pviT1quRy1i+aPdbrTb8vQjSt871rSB7zhygZMTMy7XzahdZxjKJfpxKhugB/zovJa4ybKPZyYqXQds4cSGFcXMheSjZBD5u8YYUREuQPM+VWoY7mqlcSsRezHxWgCfnzxjNUgHL9wK000/4mEQHDxAEtAdUOsG/IrNX0MqcZTOa7zLTQzTXecvhb3ivy6I/TchA9oPGMW6h8cc7MyUk3CgPIlUmfqZf/MzONy+QCqHKX7/BnVe+2jWMstgJ/oiC3y8sxhYTFm5gZx1PE+Clj3oo5O9+1RFR1bNK8DZdduDyWO5F1T84iWW1kpig3x7MctZKmcyUG1pIqzAPFZfOdaYiH+BfjWf6UITd/mX1qZqqyhw238Ui80u38UdS00EpSoipFjNbMsncN2gTN6siCUPR9/0Oh1SyT2ADI8O1EOV00mrHBJ547xb48jpsTsULdES/qgEj6kaCbelg+9uWr6+nreKvqqoGeOoNuhAzyKqEulda+AeQ8PAgORW+b+eGk2bL/+k35W6lKjvwwkqXDtJDaONwbprOiDgBJyYYv8Q6/Dyq939gCh3kHK0pJeAibgIjxJ1HOPPf4AO+6g1StljdrxvfGPqb4DprQMHfDjqnufbJm5k5YyQoz1sxf54lOBrAOPv3zXFX9tNvCDh82Kwa02froCM1h1oMCXmKCGqGZP73WsV+J/uIgPfOAZI8IuDb8N/cl5uXjjXknllABeammx4AYZGqmEfR7O0+Ze2bjgs8dEWcWuQozVPLqiFmYXjFOf3m9RaQ86SwhCI24DIfPXJuij6ac0ye8H51We3tLCkuQEXf1aoqIQe0DZz6JIsN7jzwETaOuR5U71RGp50fGzO9iL+zV/TZduZ/92dxd4+zIiQp05TFyScOH3DKjVWZxy0gPXCM32uhbvFRgggOI1rNkgvoeEcFL+ttCSUEiKJSa1essWIO6YR7IYtrcEAXued6hGzxkFt8=
- Ironport-sdr: nFfQXUGCE3kUhgmrS/P7KvQVLcE0pj1qqdYrp3mGj+VfEBS6lOT8FKhb3RXqHMMoyf4HBA2B/D QNBA1P/FWLmw==
- List-id: Mini-os development list <minios-devel.lists.xenproject.org>
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
|