Просмотр исходного кода

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.
Brian Gianforcaro 4 лет назад
Родитель
Сommit
a8765fa673
1 измененных файлов с 4 добавлено и 2 удалено
  1. 4 2
      Kernel/Syscalls/select.cpp

+ 4 - 2
Kernel/Syscalls/select.cpp

@@ -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)