From: Amos Jeffries Date: Sun, 5 May 2013 01:19:46 +0000 (-0600) Subject: Polish: better libcomm initialization and error detection X-Git-Tag: SQUID_3_4_0_1~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e42281f9a9e30718b1d1cdb1b232f7dd2ec1491d;p=thirdparty%2Fsquid.git Polish: better libcomm initialization and error detection 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 --- diff --git a/src/comm/Connection.cc b/src/comm/Connection.cc index 02477f9893..1b8d1be21a 100644 --- a/src/comm/Connection.cc +++ b/src/comm/Connection.cc @@ -19,6 +19,7 @@ Comm::Connection::Connection() : peerType(HIER_NONE), fd(-1), tos(0), + nfmark(0), flags(COMM_NONBLOCKING), peer_(NULL) { diff --git a/src/comm/TcpAcceptor.cc b/src/comm/TcpAcceptor.cc index 95bbca92a3..1696e797a9 100644 --- a/src/comm/TcpAcceptor.cc +++ b/src/comm/TcpAcceptor.cc @@ -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);