diff options
author | Eric Wong <e@80x24.org> | 2023-09-24 20:19:22 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-09-24 23:14:21 +0000 |
commit | 434a9fa1b53561e8b123534977dc82c581c46db2 (patch) | |
tree | f414d88c4c1b902bcb1a0ce641e2ccc5f19dddaa /lib/PublicInbox/Syscall.pm | |
parent | b8db6914a2a7da45cf0aed20240c8c6696a16968 (diff) | |
download | public-inbox-434a9fa1b53561e8b123534977dc82c581c46db2.tar.gz |
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.
Diffstat (limited to 'lib/PublicInbox/Syscall.pm')
-rw-r--r-- | lib/PublicInbox/Syscall.pm | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index b76a9e8a..4cf45d0f 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; |