Skip to content

Commit

Permalink
Merge pull request #14466 from ANR2ME/adhoc
Browse files Browse the repository at this point in the history
[Adhoc] Fix possible crash issue on blocking socket implementation.
  • Loading branch information
hrydgard authored May 16, 2021
2 parents 29ae351 + 8dcfed0 commit f1bf596
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Core/HLE/sceNetAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ int StartGameModeScheduler(int bufSize) {

int DoBlockingPdpRecv(int uid, AdhocSocketRequest& req, s64& result) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
if (sock->flags & ADHOC_F_ALERTRECV) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
sock->alerted_flags |= ADHOC_F_ALERTRECV;
Expand Down Expand Up @@ -495,6 +499,10 @@ int DoBlockingPdpRecv(int uid, AdhocSocketRequest& req, s64& result) {

int DoBlockingPdpSend(int uid, AdhocSocketRequest& req, s64& result, AdhocSendTargets& targetPeers) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
auto& pdpsocket = sock->data.pdp;
if (sock->flags & ADHOC_F_ALERTSEND) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
Expand Down Expand Up @@ -544,6 +552,10 @@ int DoBlockingPdpSend(int uid, AdhocSocketRequest& req, s64& result, AdhocSendTa

int DoBlockingPtpSend(int uid, AdhocSocketRequest& req, s64& result) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
auto& ptpsocket = sock->data.ptp;
if (sock->flags & ADHOC_F_ALERTSEND) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
Expand Down Expand Up @@ -593,6 +605,10 @@ int DoBlockingPtpSend(int uid, AdhocSocketRequest& req, s64& result) {

int DoBlockingPtpRecv(int uid, AdhocSocketRequest& req, s64& result) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
auto& ptpsocket = sock->data.ptp;
if (sock->flags & ADHOC_F_ALERTRECV) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
Expand Down Expand Up @@ -645,6 +661,10 @@ int DoBlockingPtpRecv(int uid, AdhocSocketRequest& req, s64& result) {

int DoBlockingPtpAccept(int uid, AdhocSocketRequest& req, s64& result) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
auto& ptpsocket = sock->data.ptp;
if (sock->flags & ADHOC_F_ALERTACCEPT) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
Expand Down Expand Up @@ -691,6 +711,10 @@ int DoBlockingPtpAccept(int uid, AdhocSocketRequest& req, s64& result) {

int DoBlockingPtpConnect(int uid, AdhocSocketRequest& req, s64& result) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
auto& ptpsocket = sock->data.ptp;
if (sock->flags & ADHOC_F_ALERTCONNECT) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
Expand Down Expand Up @@ -742,6 +766,10 @@ int DoBlockingPtpConnect(int uid, AdhocSocketRequest& req, s64& result) {

int DoBlockingPtpFlush(int uid, AdhocSocketRequest& req, s64& result) {
auto sock = adhocSockets[req.id - 1];
if (!sock) {
result = ERROR_NET_ADHOC_SOCKET_DELETED;
return 0;
}
auto& ptpsocket = sock->data.ptp;
if (sock->flags & ADHOC_F_ALERTFLUSH) {
result = ERROR_NET_ADHOC_SOCKET_ALERTED;
Expand Down Expand Up @@ -1835,6 +1863,9 @@ int PollAdhocSocket(SceNetAdhocPollSd* sds, int count, int timeout, int nonblock
// Fill in Socket ID
if (sds[i].id > 0 && sds[i].id <= MAX_SOCKET && adhocSockets[sds[i].id - 1] != NULL) {
auto sock = adhocSockets[sds[i].id - 1];
if (!sock) {
return ERROR_NET_ADHOC_SOCKET_DELETED;
}
if (sock->type == SOCK_PTP) {
fd = sock->data.ptp.id;
}
Expand Down Expand Up @@ -7230,7 +7261,7 @@ int matchingInputThread(int matchingId) // TODO: The MatchingInput thread is usi
}
else if (recvresult == 0 && rxbuflen > 0) {
WARN_LOG(SCENET, "InputLoop[%d]: Unknown Port[%s:%u] (Recved=%i, Length=%i)", matchingId, mac2str(&sendermac).c_str(), senderport, recvresult, rxbuflen);
host->NotifyUserMessage(std::string(n->T("Data from incorrect Port")) + std::string(" [") + mac2str(&sendermac) + std::string("]:") + std::to_string(senderport) + std::string(" -> ") + std::to_string(context->port), 1.0, 0x0080ff);
host->NotifyUserMessage(std::string(n->T("Data from incorrect Port")) + std::string(" [") + mac2str(&sendermac) + std::string("]:") + std::to_string(senderport) + std::string(" -> ") + std::to_string(context->port) + std::string(" (") + std::to_string(portOffset) + std::string(")"), 1.0, 0x0080ff);
}

// Handle Peer Timeouts
Expand Down

0 comments on commit f1bf596

Please sign in to comment.