Kernel: Harden sys$select Vector usage against OOM.

Theoretically the append should never fail as we have in-line storage
of FD_SETSIZE, which should always be enough. However I'm planning on
removing the non-try variants of AK::Vector when compiling in kernel
mode in the future, so this will need to go eventually. I suppose it
also protects against some unforeseen bug where we we can append more
than FD_SETSIZE items.
This commit is contained in:
Brian Gianforcaro 2021-04-29 02:27:38 -07:00 committed by Andreas Kling
parent 0ca668f59c
commit a8765fa673
Notes: sideshowbarker 2024-07-18 18:53:52 +09:00

View file

@ -78,8 +78,10 @@ KResultOr<int> Process::sys$select(Userspace<const Syscall::SC_select_params*> u
dbgln("sys$select: Bad fd number {}", fd);
return EBADF;
}
fds_info.append({ description.release_nonnull(), block_flags });
fds.append(fd);
if (!fds_info.try_append({ description.release_nonnull(), block_flags }))
return ENOMEM;
if (!fds.try_append(fd))
return ENOMEM;
}
if constexpr (IO_DEBUG || POLL_SELECT_DEBUG)