]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
`httpAddrConnect` leaked sockets in certain circumstances, causing some
authorMichael Sweet <michael.r.sweet@gmail.com>
Wed, 30 Aug 2017 00:42:05 +0000 (20:42 -0400)
committerMichael Sweet <michael.r.sweet@gmail.com>
Wed, 30 Aug 2017 00:42:05 +0000 (20:42 -0400)
printers to hang (rdar://31965686)

CHANGES.md
cups/http-addrlist.c

index d2bbe5b278cccfbb0ef7eae1de0851b11feff0e8..95a42bfeeab4cce67cd475cbefb1b1111bd6502c 100644 (file)
@@ -37,6 +37,8 @@ CHANGES IN CUPS V2.2.5
   choosing them for draft, normal, and best quality modes (Issue #5091)
 - Fixed the localization unit test on Linux (Issue #5097)
 - The CUPS library did not reuse domain sockets (Issue #5098)
+- `httpAddrConnect` leaked sockets in certain circumstances, causing some
+  printers to hang (rdar://31965686)
 - Fixed an issue with Chinese localizations on macOS (rdar://32419311)
 - The IPP backend now always sends the "finishings" attribute for printers that
   support it because otherwise the client cannot override printer defaults
index 22bd5a7d7fddddafe15f3e40a7cbe2e015d187be..e5fc940e1bdc99810d8f313de53fc6807c14cbaa 100644 (file)
@@ -65,7 +65,7 @@ httpAddrConnect2(
   int                  flags;          /* Socket flags */
 #endif /* !WIN32 */
   int                  remaining;      /* Remaining timeout */
-  int                  i,              /* Looping var */
+  int                  i, j,           /* Looping vars */
                        nfds,           /* Number of file descriptors */
                        fds[100],       /* Socket file descriptors */
                        result;         /* Result from select() or poll() */
@@ -323,6 +323,8 @@ httpAddrConnect2(
          if (!getpeername(fds[i], (struct sockaddr *)&peer, &len))
            DEBUG_printf(("1httpAddrConnect2: Connected to %s:%d...", httpAddrString(&peer, temp, sizeof(temp)), httpAddrPort(&peer)));
 #  endif /* DEBUG */
+
+          break;
        }
 #  ifdef HAVE_POLL
        else if (pfds[i].revents & (POLLERR | POLLHUP))
@@ -346,7 +348,20 @@ httpAddrConnect2(
       }
 
       if (connaddr)
+      {
+       /*
+        * Connected on one address, close all of the other sockets we have so
+        * far and return...
+        */
+
+        for (j = 0; j < i; j ++)
+          httpAddrClose(NULL, fds[j]);
+
+        for (j ++; j < nfds; j ++)
+          httpAddrClose(NULL, fds[j]);
+
         return (connaddr);
+      }
     }
 #endif /* O_NONBLOCK */