1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

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.
This commit is contained in:
Brian Gianforcaro 2021-02-21 08:03:03 -08:00 committed by Andreas Kling
parent 1c0e2947d7
commit 4743afeaf4

View file

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