From: Valentine Krasnobaeva Date: Fri, 22 Nov 2024 15:43:45 +0000 (+0100) Subject: MINOR: proto_sockpair: send_fd_uxst: init iobuf, cmsghdr, cmsgbuf to zeros X-Git-Tag: v3.1.0~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=10c14a1ed049707854614f28cd57e5fd43ec3b31;p=thirdparty%2Fhaproxy.git MINOR: proto_sockpair: send_fd_uxst: init iobuf, cmsghdr, cmsgbuf to zeros 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. --- diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index da98c62037..e9271605f2 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -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;