From 6f1a6215cb22953aef0cbcde645948c36b896ab8 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 6 Nov 2025 20:50:02 +0100 Subject: [PATCH] unix: fix use of uninitialized variable The `flags` argument to `uv__udp_recvmsg_errqueue` was not initialized in all code paths. Shuffle code around to make the control flow more obvious (at the cost of a less legible diff.) Also fixes an unused label warning when building on systems that aren't Linux. Introduced last month in commit 80a5e3ba0, "linux: add MSG_ERRQUEUE ipv4/ipv6 udp support". --- src/unix/udp.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/unix/udp.c b/src/unix/udp.c index c96a0e4e6..a3ff5d390 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -326,39 +326,29 @@ static void uv__udp_recvmsg(uv_udp_t* handle, int flag) { } #endif - do { + do nread = recvmsg(handle->io_watcher.fd, &h, flag); - } while (nread == -1 && errno == EINTR); - if (nread == -1) { -#if defined(__linux__) - if ((flag & MSG_ERRQUEUE) && - uv__udp_recvmsg_errqueue(handle, &h, &buf, - (const struct sockaddr*) &peer, flags)) { - goto out; - } -#endif - if (errno == EAGAIN || errno == EWOULDBLOCK) - handle->recv_cb(handle, 0, &buf, NULL, 0); - else - handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0); - } - else { - flags = 0; + flags = 0; + if (nread != -1) if (h.msg_flags & MSG_TRUNC) flags |= UV_UDP_PARTIAL; #if defined(__linux__) - if ((flag & MSG_ERRQUEUE) && - uv__udp_recvmsg_errqueue(handle, &h, &buf, - (const struct sockaddr*) &peer, flags)) { - goto out; - } -#endif - handle->recv_cb(handle, nread, &buf, (const struct sockaddr*) &peer, flags); + if ((flag & MSG_ERRQUEUE) && + uv__udp_recvmsg_errqueue(handle, &h, &buf, (void*) &peer, flags)) { + count--; + continue; } -out: +#endif + + if (nread != -1) + handle->recv_cb(handle, nread, &buf, (void*) &peer, flags); + else if (errno == EAGAIN || errno == EWOULDBLOCK) + handle->recv_cb(handle, 0, &buf, NULL, 0); + else + handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0); count--; } /* recv_cb callback may decide to pause or close the handle */