fix(network): prevent datagram socket SendTo errors in HDR multiplayer

Changes:
- Add validation in BSD::SendToImpl to check for empty address buffers on
  datagram sockets and return EINVAL instead of passing nullptr to sendto()
- Add null pointer check in ProxySocket::SendTo to prevent dereferencing
  nullptr address parameters
- Improve error logging to help identify socket configuration issues

Fixes: Socket operation errors in HDR multiplayer sessions
Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-08-24 16:39:39 +10:00
parent b9326b0527
commit 432d6da7c1
2 changed files with 14 additions and 0 deletions

View File

@@ -889,6 +889,14 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> mes
return {-1, Errno::BADF};
}
FileDescriptor& descriptor = *file_descriptors[fd];
// For datagram sockets (UDP), a destination address is required
if (!descriptor.is_connection_based && addr.empty()) {
LOG_ERROR(Service, "SendTo called on datagram socket without destination address");
return {-1, Errno::INVAL};
}
Network::SockAddrIn addr_in;
Network::SockAddrIn* p_addr_in = nullptr;
if (!addr.empty()) {

View File

@@ -205,6 +205,12 @@ std::pair<s32, Errno> ProxySocket::SendTo(u32 flags, std::span<const u8> message
return {static_cast<s32>(message.size()), Errno::SUCCESS};
}
// For datagram sockets, a destination address is required
if (!addr) {
LOG_ERROR(Network, "SendTo called on ProxySocket without destination address");
return {-1, Errno::INVAL};
}
if (auto room_member = room_network.GetRoomMember().lock()) {
if (!room_member->IsConnected()) {
return {static_cast<s32>(message.size()), Errno::SUCCESS};