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,AWL,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 3D5151F406 for ; Sat, 28 Oct 2023 09:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698484139; bh=Bi/IhIAMyvzykFgzPJIburbpH1YHnOHmLwPBdCgjryo=; h=From:To:Subject:Date:From; b=1rU165fbsDjo3k/9MGuBqlCTHxdugTWVoOO1+tvQcJVEW+CJP/Vn45CFxDdakHkQ/ pmn5QuzmrhJZqyDmfOv6URsKiBTo95Nn9a6/9OiUhApiUJc1KEHBpMRd05RVgWOqV5 JCa0fpRVXLqzG106WefvUgwtiOB3bqF0Ue9B0vwY= From: Eric Wong To: spew@80x24.org Subject: [PATCH] spawn: use readline instead of read for scalar redirects Date: Sat, 28 Oct 2023 09:08:59 +0000 Message-ID: <20231028090859.85819-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Using `-s $fh' as the length arg for `read' is incorrect for :utf8 and other non-:raw file handles, since `read' operates in *characters*, not bytes. --- lib/PublicInbox/Spawn.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 7dd47846..d3b7ef6f 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -22,7 +22,7 @@ use Carp qw(croak); use PublicInbox::IO; our @EXPORT_OK = qw(which spawn popen_rd popen_wr run_die run_wait run_qx); our @RLIMITS = qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA); -use autodie qw(open pipe read seek sysseek truncate); +use autodie qw(open pipe seek sysseek truncate); BEGIN { my $all_libc = <<'ALL_LIBC'; # all *nix systems we support @@ -390,10 +390,12 @@ sub popen_wr { sub read_out_err ($) { my ($opt) = @_; + local $/; for my $fd (1, 2) { # read stdout/stderr my $fh = delete($opt->{"fh.$fd"}) // next; seek($fh, 0, SEEK_SET); - read($fh, ${$opt->{$fd}}, -s $fh, length(${$opt->{$fd}} // '')); + ${$opt->{$fd}} .= <$fh>; + $fh->error and croak "E: read(FD=$fd): $!"; } }