From: Eric Wong Date: Sun, 24 Sep 2023 20:19:22 +0000 (+0000) Subject: syscall: fix valgrind error in pure Perl send_cmd4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=434a9fa1b53561e8b123534977dc82c581c46db2;p=thirdparty%2Fpublic-inbox.git syscall: fix valgrind error in pure Perl send_cmd4 We need to allocate CMSG_SPACE for the `struct cmsghdr', not the smaller CMSG_LEN. AFAIK this isn't a real world problem since the Linux kernel doesn't care about the uninitialized space as long as memory region belongs to the user, but valgrind complains. --- diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index b76a9e8a5..4cf45d0f2 100644 --- a/lib/PublicInbox/Syscall.pm +++ b/lib/PublicInbox/Syscall.pm @@ -398,10 +398,13 @@ no warnings 'once'; my ($sock, $fds, undef, $flags) = @_; my $iov = pack('P'.TMPL_size_t, $_[2] // NUL, length($_[2] // NUL) || 1); + my $fd_space = scalar(@$fds) * SIZEOF_int; + my $msg_controllen = CMSG_SPACE($fd_space); my $cmsghdr = pack(TMPL_size_t . # cmsg_len 'LL' . # cmsg_level, cmsg_type, - ('i' x scalar(@$fds)), - CMSG_LEN(scalar(@$fds) * SIZEOF_int), # cmsg_len + ('i' x scalar(@$fds)) . # CMSG_DATA + '@'.($msg_controllen - 1).'x1', # pad to space, not len + CMSG_LEN($fd_space), # cmsg_len SOL_SOCKET, SCM_RIGHTS, # cmsg_{level,type} @$fds); # CMSG_DATA my $mh = pack('PL' . # msg_name, msg_namelen (socklen_t (U32)) @@ -413,7 +416,7 @@ no warnings 'once'; @BYTES_4_hole, $iov, 1, # msg_iov, msg_iovlen $cmsghdr, # msg_control - CMSG_SPACE(scalar(@$fds) * SIZEOF_int), # msg_controllen + $msg_controllen, 0); # msg_flags my $sent; my $try = 0;