From 2b9135b3125fe8bc4bd48d15ec40b68ec033f328 Mon Sep 17 00:00:00 2001 From: lidgren Date: Fri, 10 Oct 2014 15:55:55 +0000 Subject: [PATCH] Don't try to parse packets identified as UPnP responses even when UPnP response parsing fails --- Lidgren.Network/NetPeer.Internal.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index 35bd824..1b4f0ee 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -458,21 +458,27 @@ namespace Lidgren.Network IPEndPoint ipsender = (IPEndPoint)m_senderRemote; - if (m_upnp != null && now < m_upnp.m_discoveryResponseDeadline) + if (m_upnp != null && now < m_upnp.m_discoveryResponseDeadline && bytesReceived > 32) { // is this an UPnP response? - try + string resp = System.Text.Encoding.ASCII.GetString(m_receiveBuffer, 0, bytesReceived); + if (resp.Contains("upnp:rootdevice") || resp.Contains("UPnP/1.0")) { - string resp = System.Text.Encoding.ASCII.GetString(m_receiveBuffer, 0, bytesReceived); - if (resp.Contains("upnp:rootdevice") || resp.Contains("UPnP/1.0")) + try { resp = resp.Substring(resp.ToLower().IndexOf("location:") + 9); resp = resp.Substring(0, resp.IndexOf("\r")).Trim(); m_upnp.ExtractServiceUrl(resp); return; } + catch (Exception ex) + { + LogDebug("Failed to parse UPnP response: " + ex.ToString()); + + // don't try to parse this packet further + return; + } } - catch { } } NetConnection sender = null;