]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polish: better libcomm initialization and error detection
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 5 May 2013 01:19:46 +0000 (19:19 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 5 May 2013 01:19:46 +0000 (19:19 -0600)
Initialize nfmark value on Comm::Connections to zero. Memory is init by
MemPools functionality earlier, but not necessarily now.

Check for and produce error when getsockname() call fails to identify
a local IP address on inbound connections.

 Detected by Coverity Scan. Issues 740543, 740320

src/comm/Connection.cc
src/comm/TcpAcceptor.cc

index 02477f98932c3da2f7e5d36d6095cec6b3f5934c..1b8d1be21a45a5345ef3cd84cf5f81c3e68566f8 100644 (file)
@@ -19,6 +19,7 @@ Comm::Connection::Connection() :
         peerType(HIER_NONE),
         fd(-1),
         tos(0),
+        nfmark(0),
         flags(COMM_NONBLOCKING),
         peer_(NULL)
 {
index 95bbca92a3e6e08dec1cca28424f510000c896fb..1696e797a9cbdb3a19b4afcbd41d7f74844e5b2b 100644 (file)
@@ -346,7 +346,11 @@ Comm::TcpAcceptor::oldAccept(Comm::ConnectionPointer &details)
     // lookup the local-end details of this new connection
     details->local.InitAddrInfo(gai);
     details->local.SetEmpty();
-    getsockname(sock, gai->ai_addr, &gai->ai_addrlen);
+    if (getsockname(sock, gai->ai_addr, &gai->ai_addrlen) != 0) {
+        debugs(50, DBG_IMPORTANT, "ERROR: getsockname() failed to locate local-IP on " << details << ": " << xstrerror());
+        details->local.FreeAddrInfo(gai);
+        return COMM_ERROR;
+    }
     details->local = *gai;
     details->local.FreeAddrInfo(gai);