]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: sockpair: fix build issue on macOS related to variable-length arrays
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Jan 2026 08:18:43 +0000 (09:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Jan 2026 08:26:22 +0000 (09:26 +0100)
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

index 3c3cd543e12aeee5163658aa90b71355e265cc86..da39c5e9ed1f4151c5ffa81071feaacf4a22c868 100644 (file)
@@ -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);