From b222581d18ce8503aab0ceaba78e18af777a2531 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 21 Mar 2023 21:20:43 +0200 Subject: [PATCH] Kernel: Reading from fd verifies that file is opened for reading --- kernel/kernel/Process.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 1a7a2b8e..208e37bf 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -108,6 +108,8 @@ namespace Kernel BAN::ErrorOr Process::OpenFileDescription::read(void* buffer, size_t count) { + if (!(flags & O_RDONLY)) + return BAN::Error::from_errno(EBADF); size_t n_read = TRY(inode->read(offset, buffer, count)); offset += n_read; return n_read;