diff options
author | Eric Wong <e@80x24.org> | 2023-10-28 09:12:43 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-28 17:35:42 +0000 |
commit | 3bca5c90c297c334580cffe352df6c6db4eded6b (patch) | |
tree | 3dcd196d6f45cb22c24550c1f1ed48ea7995efb4 /lib | |
parent | 9b3f8fc1d57dde120fa94d460d8cfbfdc07b7048 (diff) | |
download | public-inbox-3bca5c90c297c334580cffe352df6c6db4eded6b.tar.gz |
Using `-s $fh' as the length arg for `read' is incorrect for :utf8 and other non-:raw file handles because `read' operates in *characters*, not bytes.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/Spawn.pm | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 8382c4d2..e7d2c6ea 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -22,7 +22,7 @@ use Carp qw(croak); use PublicInbox::ProcessIO; 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): $!"; } } |