1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-05 21:07:36 +00:00

Kernel: Return error when attempting to read from a directory.

We now return EISDIR whenever a program attempts to call sys$read
on a directory. Previously, attempting to read a directory could
either return junk data or, in the case of /proc/, cause a kernel
panic.
This commit is contained in:
Drew Stratford 2019-10-25 02:46:31 +13:00 committed by Andreas Kling
parent 1be4c6e9cf
commit 489e451cce

View file

@ -1128,6 +1128,8 @@ ssize_t Process::sys$read(int fd, u8* buffer, ssize_t size)
auto* description = file_description(fd); auto* description = file_description(fd);
if (!description) if (!description)
return -EBADF; return -EBADF;
if (description->is_directory())
return -EISDIR;
if (description->is_blocking()) { if (description->is_blocking()) {
if (!description->can_read()) { if (!description->can_read()) {
if (current->block<Thread::ReadBlocker>(*description) == Thread::BlockResult::InterruptedBySignal) if (current->block<Thread::ReadBlocker>(*description) == Thread::BlockResult::InterruptedBySignal)