Fix buffer size check in UDP socket.

We were reserving 12 bytes from the buffer for ip, port, and length, but since
IPv6 introduction we should be reserving 24 (IPv6 are 16 bytes)

(cherry picked from commit 5dc7c920bf)
This commit is contained in:
Fabio Alessandrelli 2017-01-19 17:00:01 +01:00
parent 994df5df5c
commit 15ecdb5f00
2 changed files with 2 additions and 2 deletions

View File

@ -176,7 +176,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
struct sockaddr_storage from = { 0 };
socklen_t len = sizeof(struct sockaddr_storage);
int ret;
while ((ret = recvfrom(sockfd, recv_buffer, MIN((int)sizeof(recv_buffer), MAX(rb.space_left() - 12, 0)), p_wait ? 0 : MSG_DONTWAIT, (struct sockaddr *)&from, &len)) > 0) {
while ((ret = recvfrom(sockfd, recv_buffer, MIN((int)sizeof(recv_buffer), MAX(rb.space_left() - 24, 0)), p_wait ? 0 : MSG_DONTWAIT, (struct sockaddr *)&from, &len)) > 0) {
uint32_t port = 0;

View File

@ -171,7 +171,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
struct sockaddr_storage from = { 0 };
int len = sizeof(struct sockaddr_storage);
int ret;
while ((ret = recvfrom(sockfd, (char *)recv_buffer, MIN((int)sizeof(recv_buffer), MAX(rb.space_left() - 12, 0)), 0, (struct sockaddr *)&from, &len)) > 0) {
while ((ret = recvfrom(sockfd, (char *)recv_buffer, MIN((int)sizeof(recv_buffer), MAX(rb.space_left() - 24, 0)), 0, (struct sockaddr *)&from, &len)) > 0) {
uint32_t port = 0;