From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 449551F569 for ; Sun, 24 Sep 2023 20:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1695586763; bh=6BTUrU0BnRXgH6uCN8h6Nva4XDwDHfMMW8dn3bAxpxU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BaD1aowgf0UNP3B2AsuLt8Vjc4Qe1o0y6JcF7Nu2Y/CBoMm3yDyL2g7SMlHRrdTO3 jG6qi0ID9btN7S3Sf6eVZRPLkTvwNnfIQ5CHkRTjsXqgamtvg0+4lm8kJaDJdCQHSm 4W5wR0oFARelmQgcewAoUrCPGGDiPCiPVQMH4XKY= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 6/6] syscall: fix valgrind error in pure Perl send_cmd4 Date: Sun, 24 Sep 2023 20:19:22 +0000 Message-ID: <20230924201922.4031002-7-e@80x24.org> In-Reply-To: <20230924201922.4031002-1-e@80x24.org> References: <20230924201922.4031002-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/Syscall.pm | 9 ++++++--- 1 file 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;