Blame SOURCES/nspr-4.34-fix-coverity-loop-issue.patch

87e872
diff --git a/pr/src/misc/prnetdb.c b/pr/src/misc/prnetdb.c
87e872
--- a/pr/src/misc/prnetdb.c
87e872
+++ b/pr/src/misc/prnetdb.c
87e872
@@ -2209,28 +2209,38 @@ PR_GetPrefLoopbackAddrInfo(PRNetAddr *re
87e872
         PRBool result_still_empty = PR_TRUE;
87e872
         PRADDRINFO *ai = res;
87e872
         do {
87e872
             PRNetAddr aNetAddr;
87e872
 
87e872
             while (ai && ai->ai_addrlen > sizeof(PRNetAddr))
87e872
                 ai = ai->ai_next;
87e872
 
87e872
-            if (ai) {
87e872
-                /* copy sockaddr to PRNetAddr */
87e872
-                memcpy(&aNetAddr, ai->ai_addr, ai->ai_addrlen);
87e872
-                aNetAddr.raw.family = ai->ai_addr->sa_family;
87e872
+            if (!ai) {
87e872
+                break;
87e872
+            }
87e872
+
87e872
+            /* copy sockaddr to PRNetAddr */
87e872
+            memcpy(&aNetAddr, ai->ai_addr, ai->ai_addrlen);
87e872
+            aNetAddr.raw.family = ai->ai_addr->sa_family;
87e872
 #ifdef _PR_INET6
87e872
-                if (AF_INET6 == aNetAddr.raw.family)
87e872
-                    aNetAddr.raw.family = PR_AF_INET6;
87e872
+            if (AF_INET6 == aNetAddr.raw.family)
87e872
+                aNetAddr.raw.family = PR_AF_INET6;
87e872
 #endif
87e872
-                if (ai->ai_addrlen < sizeof(PRNetAddr))
87e872
-                    memset(((char*)result)+ai->ai_addrlen, 0,
87e872
-                           sizeof(PRNetAddr) - ai->ai_addrlen);
87e872
+            if (ai->ai_addrlen < sizeof(PRNetAddr))
87e872
+                memset(((char*)&aNetAddr)+ai->ai_addrlen, 0,
87e872
+                       sizeof(PRNetAddr) - ai->ai_addrlen);
87e872
+
87e872
+            if (result->raw.family == PR_AF_INET) {
87e872
+                aNetAddr.inet.port = htons(port);
87e872
             }
87e872
+            else {
87e872
+                aNetAddr.ipv6.port = htons(port);
87e872
+            }
87e872
+
87e872
 
87e872
             /* If we obtain more than one result, prefer IPv6. */
87e872
             if (result_still_empty || aNetAddr.raw.family == PR_AF_INET6) {
87e872
                 memcpy(result, &aNetAddr, sizeof(PRNetAddr));
87e872
             }
87e872
             result_still_empty = PR_FALSE;
87e872
             ai = ai->ai_next;
87e872
         }