From 85822f2eeb27058e317b8bec09b6942571d2a8e2 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Sun, 14 Feb 2021 16:18:47 +0700 Subject: [PATCH] Making sure src_addr and addrlen args of recvfrom is being set correctly upon use. --- Core/HLE/sceNetAdhoc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 8dca3921bd..e0d003769d 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -401,8 +401,8 @@ int DoBlockingPdpRecv(int uid, AdhocSocketRequest& req, s64& result) { } sockaddr_in sin; - memset(&sin, 0, sizeof(sin)); socklen_t sinlen = sizeof(sin); + memset(&sin, 0, sinlen); // On Windows: MSG_TRUNC are not supported on recvfrom (socket error WSAEOPNOTSUPP), so we use dummy buffer as an alternative int ret = recvfrom(uid, dummyPeekBuf64k, dummyPeekBuf64kSize, MSG_PEEK | MSG_NOSIGNAL, (sockaddr*)&sin, &sinlen); @@ -412,6 +412,8 @@ int DoBlockingPdpRecv(int uid, AdhocSocketRequest& req, s64& result) { // Note: UDP must not be received partially, otherwise leftover data in socket's buffer will be discarded if (ret >= 0 && ret <= *req.length) { + sinlen = sizeof(sin); + memset(&sin, 0, sinlen); ret = recvfrom(uid, (char*)req.buffer, *req.length, MSG_NOSIGNAL, (sockaddr*)&sin, &sinlen); // UDP can also receives 0 data, while on TCP receiving 0 data = connection gracefully closed, but not sure whether PDP can send/recv 0 data or not tho *req.length = 0; @@ -1662,6 +1664,7 @@ static int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void * // Set Address Length (so we get the sender ip) socklen_t sinlen = sizeof(sin); + memset(&sin, 0, sinlen); //sin.sin_len = (uint8_t)sinlen; // Acquire Network Lock @@ -1703,6 +1706,8 @@ static int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void * return hleLogSuccessVerboseI(SCENET, ERROR_NET_ADHOC_NOT_ENOUGH_SPACE, "not enough space"); //received; } + sinlen = sizeof(sin); + memset(&sin, 0, sinlen); received = recvfrom(pdpsocket.id, (char*)buf, *len, MSG_NOSIGNAL, (sockaddr*)&sin, &sinlen); error = errno;