* [PATCH 6/6] syscall: fix valgrind error in pure Perl send_cmd4
2023-09-24 20:19 6% [PATCH 0/6] various test and syscall-related fixes Eric Wong
@ 2023-09-24 20:19 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-09-24 20:19 UTC (permalink / raw)
To: meta
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;
^ permalink raw reply related [relevance 7%]
* [PATCH 0/6] various test and syscall-related fixes
@ 2023-09-24 20:19 6% Eric Wong
2023-09-24 20:19 7% ` [PATCH 6/6] syscall: fix valgrind error in pure Perl send_cmd4 Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-09-24 20:19 UTC (permalink / raw)
To: meta
A few fixes I noticed while working on some other lei-related cleanups.
Eric Wong (6):
test_common: fixes for TEST_RUN_MODE=0
t/cmd_ipc: assume SOCK_SEQPACKET
lei_self_socket: drop unused deps and code
ipc: recv_cmd4 clobbers destination buffer on errors
syscall: have `vec' operate on bytes directly
syscall: fix valgrind error in pure Perl send_cmd4
lib/PublicInbox/CmdIPC4.pm | 5 +++-
lib/PublicInbox/LEI.pm | 1 -
lib/PublicInbox/LeiSelfSocket.pm | 8 ++-----
lib/PublicInbox/Spawn.pm | 8 ++++---
lib/PublicInbox/Syscall.pm | 20 ++++++++++------
lib/PublicInbox/TestCommon.pm | 1 +
t/cmd_ipc.t | 40 +++++++++++++++-----------------
7 files changed, 44 insertions(+), 39 deletions(-)
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-24 20:19 6% [PATCH 0/6] various test and syscall-related fixes Eric Wong
2023-09-24 20:19 7% ` [PATCH 6/6] syscall: fix valgrind error in pure Perl send_cmd4 Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).