]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proto_sockpair: send_fd_uxst: init iobuf, cmsghdr, cmsgbuf to zeros
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Fri, 22 Nov 2024 15:43:45 +0000 (16:43 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 25 Nov 2024 14:20:24 +0000 (15:20 +0100)
In master-worker mode, worker process uses now send_fd_uxst() to send
'_send_status' command to master. Since refactoring, this started to trigger
the following Valgrind reports:

==810584== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
==810584==    at 0x4AAC99D: __libc_sendmsg (sendmsg.c:28)
==810584==    by 0x4AAC99D: sendmsg (sendmsg.c:25)
==810584==    by 0x56350F: send_fd_uxst (proto_sockpair.c:271)
==810584==    by 0x3AA25C: main (haproxy.c:4151)
==810584==  Address 0x1ffefffbfe is on thread 1's stack
==810584==  in frame #1, created by send_fd_uxst (proto_sockpair.c:241)
==810584==
==810584== Syscall param sendmsg(msg.msg_control) points to uninitialised byte(s)
==810584==    at 0x4AAC99D: __libc_sendmsg (sendmsg.c:28)
==810584==    by 0x4AAC99D: sendmsg (sendmsg.c:25)
==810584==    by 0x56350F: send_fd_uxst (proto_sockpair.c:271)
==810584==    by 0x3AA25C: main (haproxy.c:4151)
==810584==  Address 0x1ffefffc14 is on thread 1's stack
==810584==  in frame #1, created by send_fd_uxst (proto_sockpair.c:241)
==810584==

So, let's initialize with zeros all buffers, which are passed to sendmsg
syscall(), used in send_fd_uxst() to avoid these Valgrind messages. They
increase Valgrind output and could make unnoticeable some other, more important
reports.

src/proto_sockpair.c

index da98c620377a09e34edc776c40c7917882151bf0..e9271605f27b0fd28678d3bc5803fcbe20dfef71 100644 (file)
@@ -239,12 +239,12 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e
  */
 int send_fd_uxst(int fd, int send_fd)
 {
-       char iobuf[2];
+       char iobuf[2] = {0};
        struct iovec iov;
        struct msghdr msghdr;
 
-       char cmsgbuf[CMSG_SPACE(sizeof(int))];
-       char buf[CMSG_SPACE(sizeof(int))];
+       char cmsgbuf[CMSG_SPACE(sizeof(int))] = {0};
+       char buf[CMSG_SPACE(sizeof(int))] = {0};
        struct cmsghdr *cmsg = (void *)buf;
 
        int *fdptr;