From 95c57462cc4f580be91989e28a9ef3e9eceb6f19 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 12 Jul 2024 18:21:47 +0100 Subject: [PATCH] DEV9: FreeBSD/Mac Fixes for ICMP session --- pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp index 96692d4ef7..bb8aa21de1 100644 --- a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp +++ b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp @@ -128,7 +128,8 @@ namespace Sessions icmpResponseBufferLen = 8 + requestSize + 8; #elif defined(ICMP_SOCKETS_BSD) // Returned IP Header, ICMP Header & either data or failed ICMP packet - icmpResponseBufferLen = 20 + 8 + std::max(20 + 8, requestSize); + // Sometimes get full packet in ICMP error response + icmpResponseBufferLen = 20 + 8 + (20 + 8 + requestSize); #endif break; } @@ -464,12 +465,15 @@ namespace Sessions { // Extract the packet the ICMP message is responding to IP_Packet ipPacket(icmpPayload->data, icmpPayload->GetLength(), true); + + if (ipPacket.protocol != static_cast(IP_Type::ICMP)) + return nullptr; + IP_PayloadPtr* ipPayload = static_cast(ipPacket.GetPayload()); - // TODO, validate proto? - ICMP_Packet retIcmp(ipPayload->data, ipPayload->GetLength()); + ICMP_Packet icmpInner(ipPayload->data, ipPayload->GetLength()); // Check if response is for us - ICMP_HeaderDataIdentifier headerData(icmp.headerData); + ICMP_HeaderDataIdentifier headerData(icmpInner.headerData); if (headerData.identifier != icmpId) return nullptr;