mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Merge pull request #13826 from ANR2ME/adhoc
Using MSG_TRUNC along with MSG_PEEK as a precaution of a possible buffer overflow when peeking recv buffer
This commit is contained in:
commit
8d2fdfc739
1 changed files with 2 additions and 2 deletions
|
@ -404,7 +404,7 @@ int DoBlockingPdpRecv(int uid, AdhocSocketRequest& req, s64& result) {
|
|||
memset(&sin, 0, sizeof(sin));
|
||||
socklen_t sinlen = sizeof(sin);
|
||||
|
||||
int ret = recvfrom(uid, (char*)req.buffer, *req.length, MSG_PEEK | MSG_NOSIGNAL, (sockaddr*)&sin, &sinlen);
|
||||
int ret = recvfrom(uid, (char*)req.buffer, *req.length, MSG_PEEK | MSG_NOSIGNAL | MSG_TRUNC, (sockaddr*)&sin, &sinlen);
|
||||
int sockerr = errno;
|
||||
|
||||
// Note: UDP must not be received partially, otherwise leftover data in socket's buffer will be discarded
|
||||
|
@ -1673,7 +1673,7 @@ static int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void *
|
|||
|
||||
// Receive Data. PDP always sent in full size or nothing(failed), recvfrom will always receive in full size as requested (blocking) or failed (non-blocking). If available UDP data is larger than buffer, excess data is lost.
|
||||
// Should peek first for the available data size if it's more than len return ERROR_NET_ADHOC_NOT_ENOUGH_SPACE along with required size in len to prevent losing excess data
|
||||
received = recvfrom(pdpsocket.id, (char*)buf, *len, MSG_PEEK | MSG_NOSIGNAL, (sockaddr*)&sin, &sinlen);
|
||||
received = recvfrom(pdpsocket.id, (char*)buf, *len, MSG_PEEK | MSG_NOSIGNAL | MSG_TRUNC, (sockaddr*)&sin, &sinlen);
|
||||
if (received != SOCKET_ERROR && *len < received) {
|
||||
WARN_LOG(SCENET, "sceNetAdhocPdpRecv[%i:%u]: Peeked %u/%u bytes from %s:%u\n", id, getLocalPort(pdpsocket.id), received, *len, inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
|
||||
*len = received;
|
||||
|
|
Loading…
Add table
Reference in a new issue