Fix uninitialized memory usage when UPNP_GetValidIGD() returns 3

This commit is contained in:
Cameron Gutman 2018-10-20 18:31:33 -07:00
parent 9a95d075e6
commit dad9b01a6f
2 changed files with 35 additions and 32 deletions

View File

@ -269,6 +269,10 @@ bool UPnPHandleDeviceList(struct UPNPDev* list, bool ipv6, bool enable)
printf("No UPnP device found!" NL);
return false;
}
else if (ret == 3) {
printf("No UPnP IGD found!" NL);
goto Exit;
}
else if (ret == 1) {
printf("Found a connected UPnP IGD" NL);
}
@ -278,12 +282,6 @@ bool UPnPHandleDeviceList(struct UPNPDev* list, bool ipv6, bool enable)
// Even if we are able to add forwarding entries, go ahead and try NAT-PMP
success = false;
}
else if (ret == 3) {
printf("Found UPnP devices (assuming it's an IGD) (!)" NL);
// Even if we are able to add forwarding entries, go ahead and try NAT-PMP
success = false;
}
else {
printf("UPNP_GetValidIGD() failed: %d" NL, ret);
goto Exit;

View File

@ -529,6 +529,8 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, bool* foundPortForwardingRules)
char wanAddrStr[128];
int ret = UPNP_GetValidIGD(ipv4Devs, &urls, &data, myAddr, sizeof(myAddr));
if (ret != 0) {
// Connected or disconnected IGD
if (ret == 1 || ret == 2) {
ret = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, wanAddrStr);
if (ret == UPNPCOMMAND_SUCCESS) {
wanAddr->sin_addr.S_un.S_addr = inet_addr(wanAddrStr);
@ -558,6 +560,9 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, bool* foundPortForwardingRules)
}
}
}
FreeUPNPUrls(&urls);
}
}
// Use the delay of upnpDiscoverAll() to also allow the NAT-PMP endpoint time to respond