From 7f13dbfa1612583bea836089382348601652c506 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Sun, 3 Dec 2023 22:58:24 -0500 Subject: [PATCH] vfs: fix edge case when returned fd is null --- fs/vfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/vfs.c b/fs/vfs.c index 562ffd4..88dd6a9 100644 --- a/fs/vfs.c +++ b/fs/vfs.c @@ -156,6 +156,11 @@ DIR *opendir(const char *name) if (!fdesc) return NULL; + if (fdesc->fd < 0) { + slab_free(fd_slab, fdesc); + return NULL; + } + struct fs *fs = fdesc->fs; if ((fdesc->vnode.flags & VFS_VTYPE_MASK) != VFS_VNO_DIR) {