summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-04-30 03:18:10 -0700
committerLinus Groh <mail@linusgroh.de>2021-05-01 09:10:30 +0200
commit2ee1731966427b8ce17246a4f8254f91f885ea98 (patch)
treea84c488d8685bfb397ab75758efb123a8afed556 /Kernel
parentee84b8a845176701ed8fc90076795bae841044c2 (diff)
downloadserenity-2ee1731966427b8ce17246a4f8254f91f885ea98.zip
Kernel: Harden Process Vector usage against OOM.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index c9ab5377f6..d9df7ba326 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -146,7 +146,10 @@ RefPtr<Process> Process::create_user_process(RefPtr<Thread>& first_thread, const
auto process = adopt_ref(*new Process(first_thread, parts.take_last(), uid, gid, parent_pid, false, move(cwd), nullptr, tty));
if (!first_thread)
return {};
- process->m_fds.resize(m_max_open_file_descriptors);
+ if (!process->m_fds.try_resize(m_max_open_file_descriptors)) {
+ first_thread = nullptr;
+ return {};
+ }
auto& device_to_use_as_tty = tty ? (CharacterDevice&)*tty : NullDevice::the();
auto description = device_to_use_as_tty.open(O_RDWR).value();
process->m_fds[0].set(*description);