Browse Source

Kernel: Use already computed nfds_checked value when copying from user mode.

- We've already computed the number of fds * sizeof(pollfd), so use it
  instead of needlessly doing it again.

- Use fds_copy.data() instead off address of indexing the vector.
Brian Gianforcaro 4 years ago
parent
commit
4743afeaf4
1 changed files with 2 additions and 2 deletions
  1. 2 2
      Kernel/Syscalls/select.cpp

+ 2 - 2
Kernel/Syscalls/select.cpp

@@ -169,7 +169,7 @@ int Process::sys$poll(Userspace<const Syscall::SC_poll_params*> user_params)
         if (nfds_checked.has_overflow())
             return -EFAULT;
         fds_copy.resize(params.nfds);
-        if (!copy_from_user(&fds_copy[0], &params.fds[0], params.nfds * sizeof(pollfd)))
+        if (!copy_from_user(fds_copy.data(), &params.fds[0], nfds_checked.value()))
             return -EFAULT;
     }
 
@@ -242,7 +242,7 @@ int Process::sys$poll(Userspace<const Syscall::SC_poll_params*> user_params)
             fds_with_revents++;
     }
 
-    if (params.nfds > 0 && !copy_to_user(&params.fds[0], &fds_copy[0], params.nfds * sizeof(pollfd)))
+    if (params.nfds > 0 && !copy_to_user(&params.fds[0], fds_copy.data(), params.nfds * sizeof(pollfd)))
         return -EFAULT;
 
     return fds_with_revents;