summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
authorTrond Abusdal <trond.abusdal@gmail.com>2015-11-09 01:33:16 +0100
committerTrond Abusdal <trond.abusdal@gmail.com>2015-11-09 01:33:16 +0100
commit41a161647dd8f3f0bfa5727ee1b357ea8605c348 (patch)
tree06cbfb60bf3e4643428c0fa1feabfc670c50bacc /drivers/unix
parentf809cd44eabbf3f0a263cb625b60adeb8f6802f0 (diff)
* Winsock UDP messages sent to an unavailable target causing WSAECONNRESET will no longer close the socket.
* Ensured that unsigned<->signed conversion would not cause wrong buffer size values sent to recvfrom.
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/packet_peer_udp_posix.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp
index fd94f0e3bf..8e28dd5bca 100644
--- a/drivers/unix/packet_peer_udp_posix.cpp
+++ b/drivers/unix/packet_peer_udp_posix.cpp
@@ -120,8 +120,10 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
struct sockaddr_in from = {0};
socklen_t len = sizeof(struct sockaddr_in);
+ int rb_size = MAX(rb.space_left()-12, 0);
+ int buffer_size = MIN((int)sizeof(recv_buffer),rb_size);
int ret;
- while ( (ret = recvfrom(sockfd, recv_buffer, MIN(sizeof(recv_buffer),rb.space_left()-12), p_wait?0:MSG_DONTWAIT, (struct sockaddr*)&from, &len)) > 0) {
+ while ( (ret = recvfrom(sockfd, recv_buffer, buffer_size, p_wait?0:MSG_DONTWAIT, (struct sockaddr*)&from, &len)) > 0) {
rb.write((uint8_t*)&from.sin_addr, 4);
uint32_t port = ntohs(from.sin_port);
rb.write((uint8_t*)&port, 4);
@@ -131,6 +133,8 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
++queue_count;
};
+
+ // TODO: Should ECONNRESET be handled here?
if (ret == 0 || (ret == -1 && errno != EAGAIN) ) {
close();
return FAILED;