From: Guy Harris Date: Mon, 7 Jan 2019 04:22:45 +0000 (-0800) Subject: Don't tell the client if we can't turn non-blocking mode off. X-Git-Tag: libpcap-1.10-bp~671 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/40b4666b567b234a5d8c2ae802c290d49758834a Don't tell the client if we can't turn non-blocking mode off. If the control socket is in non-blocking mode, there's no guarantee that we can easily send an error message to the client - we *probably* can, but let's not rely on it, especially given that there are "shouldn't happen" errors. Log them instead. While we're at it, fix a copy-and-pasteo and fix indentation. --- diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c index 0509147a..5d9dd343 100644 --- a/rpcapd/rpcapd.c +++ b/rpcapd/rpcapd.c @@ -1193,17 +1193,25 @@ accept_connection(SOCKET listen_sock) // First, we have to un-WSAEventSelect() this socket, and then // we can turn non-blocking mode off. // + // If this fails, we aren't guaranteed that, for example, any + // of the error message will be sent - if it can't be put in + // the socket queue, the send will just fail. + // + // So we just log the message and close the connection. + // if (WSAEventSelect(sockctrl, NULL, 0) == SOCKET_ERROR) { - sock_geterror("ioctlsocket(FIONBIO): ", errbuf, PCAP_ERRBUF_SIZE); - rpcap_senderror(sockctrl, ssl, 0, PCAP_ERR_HOSTNOAUTH, errbuf, NULL); - goto error; + sock_geterror("WSAEventSelect: ", errbuf, PCAP_ERRBUF_SIZE); + rpcapd_log(LOGPRIO_ERROR, "%s", errbuf); + sock_close(sockctrl, NULL, 0); + return; } if (ioctlsocket(sockctrl, FIONBIO, &off) == SOCKET_ERROR) { sock_geterror("ioctlsocket(FIONBIO): ", errbuf, PCAP_ERRBUF_SIZE); - rpcap_senderror(sockctrl, ssl, 0, PCAP_ERR_HOSTNOAUTH, errbuf, NULL); - goto error; + rpcapd_log(LOGPRIO_ERROR, "%s", errbuf); + sock_close(sockctrl, NULL, 0); + return; } // @@ -1289,7 +1297,7 @@ accept_connection(SOCKET listen_sock) #endif closesocket(sockctrl); #endif - return; + return; error: #ifdef _WIN32