From 2d6b461d0f4e9bc28cf576e7280da18781e8f943 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jan 2020 13:24:41 +0200 Subject: [PATCH] Disallow opening dirs without O_DIRECTORY and vice versa --- sys/vfs/vfs_ops.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/vfs/vfs_ops.c b/sys/vfs/vfs_ops.c index 019878e..287f685 100644 --- a/sys/vfs/vfs_ops.c +++ b/sys/vfs/vfs_ops.c @@ -184,6 +184,10 @@ int vfs_open_vnode(struct vfs_ioctx *ctx, struct ofile *fd, struct vnode *node, _assert(node); if (opt & O_DIRECTORY) { + if (node->type != VN_DIR) { + return -ENOTDIR; + } + if ((opt & O_ACCMODE) != O_RDONLY) { return -EACCES; } @@ -198,6 +202,8 @@ int vfs_open_vnode(struct vfs_ioctx *ctx, struct ofile *fd, struct vnode *node, } return 0; + } else if (node->type == VN_DIR || node->type == VN_MNT) { + return -EISDIR; } // Check node access