From 5bc15a222694d30f62721eecb3d99b7be006f971 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 26 Apr 2024 14:25:49 -0400 Subject: kernel: filedesc: Ensure write() fd is correct Signed-off-by: Ian Moffett --- sys/kern/kern_filedesc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sys/kern') diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c index b95d123..7e65d77 100644 --- a/sys/kern/kern_filedesc.c +++ b/sys/kern/kern_filedesc.c @@ -242,6 +242,10 @@ write(int fd, const void *buf, size_t count) } desc = fd_from_fdnum(td, fd); + if (desc == NULL) { + return -EBADF; + } + if (desc->oflag != O_WRONLY && desc->oflag != O_WRONLY) { ret = -EACCES; goto cleanup; -- cgit v1.2.3