1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-03 00:52:12 +00:00

Kernel: Report AF_UNIX address family when accepting local sockets

Previously we just wrote the local socket bind path into the sockaddr_un
buffer. With this patch, we actually report the family as well.
This commit is contained in:
Andreas Kling 2022-04-21 16:23:05 +02:00
parent 612dbdc671
commit 8e9676c28c

View file

@ -100,14 +100,20 @@ LocalSocket::~LocalSocket()
void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
{
auto& address_un = *reinterpret_cast<sockaddr_un*>(address);
address_un = {
.sun_family = AF_UNIX,
.sun_path = {},
};
if (!m_path || m_path->is_empty()) {
size_t bytes_to_copy = min(static_cast<size_t>(*address_size), sizeof(sockaddr_un));
memset(address, 0, bytes_to_copy);
} else {
size_t bytes_to_copy = min(m_path->length(), min(static_cast<size_t>(*address_size), sizeof(sockaddr_un)));
memcpy(address, m_path->characters(), bytes_to_copy);
*address_size = sizeof(address_un.sun_family);
return;
}
*address_size = sizeof(sockaddr_un);
size_t bytes_to_copy = min(m_path->length() + 1, min(static_cast<size_t>(*address_size), sizeof(address_un.sun_path)));
memcpy(address_un.sun_path, m_path->characters(), bytes_to_copy);
*address_size = sizeof(address_un.sun_family) + bytes_to_copy;
}
void LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size)