]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix UDP log module opening and closing code (#2214)
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Wed, 10 Sep 2025 00:57:09 +0000 (00:57 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 10 Sep 2025 00:57:19 +0000 (00:57 +0000)
logfile_mod_udp_open() mistreated successful comm_connect_addr() result
as an "Unable to connect" failure (and vice versa), rendering UDP-based
logging unusable. Broken since at least 2010 commit d938215.

Also fixed logfile_mod_udp_close() closing FD 0 after "Invalid UDP
logging address" ERRORs during logfile_mod_udp_open().

src/log/ModUdp.cc

index d4ad05611aa3ea9cb8f5cbeec7461f6c0409cc32..8d279cc606f7920d5b47d2c2e538539173e4016c 100644 (file)
@@ -145,6 +145,7 @@ logfile_mod_udp_open(Logfile * lf, const char *path, size_t bufsz, int fatal_fla
     lf->f_rotate = logfile_mod_udp_rotate;
 
     l_udp_t *ll = static_cast<l_udp_t*>(xcalloc(1, sizeof(*ll)));
+    ll->fd = -1;
     lf->data = ll;
 
     if (strncmp(path, "//", 2) == 0) {
@@ -178,7 +179,7 @@ logfile_mod_udp_open(Logfile * lf, const char *path, size_t bufsz, int fatal_fla
             debugs(50, DBG_IMPORTANT, "ERROR: Unable to open UDP socket for logging");
             return FALSE;
         }
-    } else if (!comm_connect_addr(ll->fd, addr)) {
+    } else if (comm_connect_addr(ll->fd, addr) == Comm::COMM_ERROR) {
         xerrno = errno;
         if (lf->flags.fatal) {
             fatalf("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerr(xerrno));