diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-07 23:42:28 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-07 23:43:32 +0100 |
commit | d04fcccc90dfa99031e5e16c2b2be7a31e613520 (patch) | |
tree | bdcc5a39f8150129303fe529cfa2481ffd4a5876 /Kernel/Net/LocalSocket.cpp | |
parent | d34ad44f90fbfc9f4166d8326994aa86458a18d5 (diff) | |
download | serenity-d04fcccc90dfa99031e5e16c2b2be7a31e613520.zip |
Kernel: Truncate addresses stored by getsockname() and getpeername()
If there's not enough space in the output buffer for the whole sockaddr
we now simply truncate the address instead of returning EINVAL.
This patch also makes getpeername() actually return the peer address
rather than the local address.. :^)
Diffstat (limited to 'Kernel/Net/LocalSocket.cpp')
-rw-r--r-- | Kernel/Net/LocalSocket.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 68269a82a0..a364336799 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -76,19 +76,16 @@ LocalSocket::~LocalSocket() all_sockets().resource().remove(this); } -bool LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size) +void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size) { - // FIXME: Look into what fallback behavior we should have here. - if (*address_size != sizeof(sockaddr_un)) - return false; - memcpy(address, &m_address, sizeof(sockaddr_un)); + size_t bytes_to_copy = min(static_cast<size_t>(*address_size), sizeof(sockaddr_un)); + memcpy(address, &m_address, bytes_to_copy); *address_size = sizeof(sockaddr_un); - return true; } -bool LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size) +void LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size) { - return get_local_address(address, address_size); + get_local_address(address, address_size); } KResult LocalSocket::bind(const sockaddr* user_address, socklen_t address_size) |