Author Topic: Bug in TNUPnP.cs (ParseResponse)  (Read 2159 times)

Kerozard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Bug in TNUPnP.cs (ParseResponse)
« on: September 01, 2017, 02:32:50 AM »
I have been getting this exception with V3.0.9 and decided to look into it a bit.

  1. UPnP: Cannot be negative.
  2. Parameter name: length
  3. UnityEngine.Debug:LogError(Object)
  4. TNet.UPnP:ThreadDiscover(Object) (at Assets/TNet/Common/TNUPnP.cs:193)
  5.  

It gets thrown when the baseUrl in ParseResponse is "http://192.168.0.12:9080". The issue is caused in line 227. The code is trying to find the first slash after the http:// and fails to accomodate for the case when there is none by subsequently calling
  1. mGatewayURL = baseURL.Substring(0, offset);
with an offset of -1.

I hope posting one line of proprietary source does not get me banned. :-P

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Bug in TNUPnP.cs (ParseResponse)
« Reply #1 on: September 01, 2017, 05:44:12 PM »
  1. int offset = baseURL.IndexOf("://");
  2. int endOffset = baseURL.IndexOf('/', offset + 3);
  3. if (endOffset > 0)
  4.         mGatewayURL = baseURL.Substring(0, endOffset);
  5. else
  6.         mGatewayURL = baseURL;
  7.  

I'm sure you've already fixed it, but posting the fix here for ArenMook.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug in TNUPnP.cs (ParseResponse)
« Reply #2 on: September 06, 2017, 12:48:22 AM »
I'll make the change, thanks!