From dbba442740235e9c5f4a513e7b3b29ea05d3d2f9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 8 Jan 2026 09:18:43 +0100 Subject: [PATCH] BUILD: sockpair: fix build issue on macOS related to variable-length arrays In GH issue #3226, Sergey Fedorov (@barracuda156) reported that since commit 10c14a1ed0 ("MINOR: proto_sockpair: send_fd_uxst: init iobuf, cmsghdr, cmsgbuf to zeros"), macOS 10.6.8 with gcc 14.3.0 doesn't build anymore: src/proto_sockpair.c: In function 'send_fd_uxst': src/proto_sockpair.c:246:49: error: variable-sized object may not be initialized except with an empty initializer 246 | char cmsgbuf[CMSG_SPACE(sizeof(int))] = {0}; | ^ src/proto_sockpair.c:247:45: error: variable-sized object may not be initialized except with an empty initializer 247 | char buf[CMSG_SPACE(sizeof(int))] = {0}; | ^ Upon investigation, it appears that the CMSG_SPACE() macro on this OS looks too complex for gcc to consider it as a constant, so it takes these buffers for variable-length arrays and cannot initialize them. Let's move to a simple memset() instead, which Sergey confirmed fixes the problem. This needs to be backported as far as 3.1. Thanks to Sergey for the report, the bisect and testing the fix. --- src/proto_sockpair.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index 3c3cd543e..da39c5e9e 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -237,12 +237,15 @@ int send_fd_uxst(int fd, int send_fd) struct iovec iov; struct msghdr msghdr; - char cmsgbuf[CMSG_SPACE(sizeof(int))] = {0}; - char buf[CMSG_SPACE(sizeof(int))] = {0}; + char cmsgbuf[CMSG_SPACE(sizeof(int))]; + char buf[CMSG_SPACE(sizeof(int))]; struct cmsghdr *cmsg = (void *)buf; int *fdptr; + memset(cmsgbuf, 0, sizeof(cmsgbuf)); + memset(buf, 0, sizeof(buf)); + iov.iov_base = iobuf; iov.iov_len = sizeof(iobuf);