Bug 1271131 - check inet_ntoa return code before use, r=mcmanus
authorDaniel Stenberg <daniel@haxx.se>
Sun, 08 May 2016 14:25:00 +0200
changeset 321106 8389ea0503283e0cd5146036bcee10d76521b594
parent 321105 1fa8b9b2a6b6f96d5d7810a589be15b38f021369
child 321107 c266d77492fbd9bad44e020a7782add0b13f8a4a
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1271131
milestone49.0a1
Bug 1271131 - check inet_ntoa return code before use, r=mcmanus
netwerk/system/win32/nsNotifyAddrListener.cpp
--- a/netwerk/system/win32/nsNotifyAddrListener.cpp
+++ b/netwerk/system/win32/nsNotifyAddrListener.cpp
@@ -240,25 +240,26 @@ static bool defaultgw(char *gateway) // 
 
     DWORD retVal = GetIpForwardTable(pIpForwardTable, &dwSize, 0);
     if (retVal == NO_ERROR) {
         for (unsigned int i = 0; i < pIpForwardTable->dwNumEntries; ++i) {
             // Convert IPv4 addresses to strings
             struct in_addr IpAddr;
             IpAddr.S_un.S_addr = static_cast<u_long>
                 (pIpForwardTable->table[i].dwForwardDest);
-            char szDestIp[128];
-            strcpy_s(szDestIp, sizeof (szDestIp), inet_ntoa(IpAddr));
-
-            if (!strcmp("0.0.0.0", szDestIp)) {
+            char *ipStr = inet_ntoa(IpAddr);
+            if (ipStr && !strcmp("0.0.0.0", ipStr)) {
                 // Default gateway!
                 IpAddr.S_un.S_addr = static_cast<u_long>
                     (pIpForwardTable->table[i].dwForwardNextHop);
-                strcpy_s(gateway, 128, inet_ntoa(IpAddr));
-                return true;
+                ipStr = inet_ntoa(IpAddr);
+                if (ipStr) {
+                    strcpy_s(gateway, 128, ipStr);
+                    return true;
+                }
             }
         } // for loop
     }
 
     return false;
 }
 
 //