diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index eb26c97327f..5f8b3a7374e 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -3157,13 +3157,14 @@ int Process::sys$listen(int sockfd, int backlog) return socket.listen(backlog); } -int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* address_size) +int Process::sys$accept(int accepting_socket_fd, sockaddr* user_address, socklen_t* user_address_size) { REQUIRE_PROMISE(accept); - if (!validate_write_typed(address_size)) + if (!validate_write_typed(user_address_size)) return -EFAULT; - SmapDisabler disabler; - if (!validate_write(address, *address_size)) + socklen_t address_size = 0; + copy_from_user(&address_size, user_address_size); + if (!validate_write(user_address, address_size)) return -EFAULT; int accepted_socket_fd = alloc_fd(); if (accepted_socket_fd < 0) @@ -3184,7 +3185,13 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a } auto accepted_socket = socket.accept(); ASSERT(accepted_socket); - accepted_socket->get_peer_address(address, address_size); + + u8 address_buffer[sizeof(sockaddr_un)]; + address_size = min(sizeof(sockaddr_un), static_cast(address_size)); + accepted_socket->get_peer_address((sockaddr*)address_buffer, &address_size); + copy_to_user(user_address, address_buffer, address_size); + copy_to_user(user_address_size, &address_size); + auto accepted_socket_description = FileDescription::create(*accepted_socket); accepted_socket_description->set_readable(true); accepted_socket_description->set_writable(true);