]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Do not make bogus recvmsg(2) calls when closing UDS sockets.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 30 Jun 2016 20:51:54 +0000 (08:51 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 30 Jun 2016 20:51:54 +0000 (08:51 +1200)
comm_empty_os_read_buffers() assumes that all non-blocking
FD_READ_METHODs can read into an opaque buffer filled with random
characters. That assumption is wrong for UDS sockets that require an
initialized msghdr structure. Feeding random data to recvmsg(2) leads to
confusing errors, at best. Squid does not log those errors, but they
are visible in, for example, strace:

  recvmsg(17, 0x7fffbb, MSG_DONTWAIT) = -1 EMSGSIZE (Message too long)

comm_empty_os_read_buffers() is meant to prevent TCP RST packets. The
function now ignores UDS sockets that are not used for TCP.

TODO: Useless reads may also exist for UDP and some TCP sockets.

src/comm.cc

index f0f78ff3202f64f19e82927c094687cdfd5bb68b..1b8bbb39fed4e3916653eb6fc7802b44582426b3 100644 (file)
@@ -110,7 +110,7 @@ comm_empty_os_read_buffers(int fd)
 
     /* prevent those nasty RST packets */
     char buf[SQUID_TCP_SO_RCVBUF];
-    if (fd_table[fd].flags.nonblocking) {
+    if (fd_table[fd].flags.nonblocking && fd_table[fd].type != FD_MSGHDR) {
         while (FD_READ_METHOD(fd, buf, SQUID_TCP_SO_RCVBUF) > 0) {};
     }
 #endif