about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-24 14:23:35 +0500
committerEric Wong <e@80x24.org>2021-03-24 23:01:21 +0000
commit69175b02c000d3ff5f03e5a88701468f121af4b6 (patch)
treea44663dd3e58c6e4a4140510a8661b67f900e456 /lib
parent636604567b8ff6118c5fcf25e2912a50e0050ca2 (diff)
downloadpublic-inbox-69175b02c000d3ff5f03e5a88701468f121af4b6.tar.gz
If a client passes us the incorrect number of FDs, we'll vivify
them into PerlIO objects so they can be auto-closed.  Using
POSIX::close was considered, but it would've been more code to
handle an uncommon case.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LEI.pm15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 878685f1..e5211764 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -981,17 +981,16 @@ sub accept_dispatch { # Listener {post_accept} callback
                 return send($sock, 'timed out waiting to recv FDs', MSG_EOR);
         # (4096 * 33) >MAX_ARG_STRLEN
         my @fds = $recv_cmd->($sock, my $buf, 4096 * 33) or return; # EOF
-        if (scalar(@fds) == 4) {
-                for my $i (0..3) {
-                        my $fd = shift(@fds);
-                        open($self->{$i}, '+<&=', $fd) and next;
-                        send($sock, "open(+<&=$fd) (FD=$i): $!", MSG_EOR);
-                }
-        } elsif (!defined($fds[0])) {
+        if (!defined($fds[0])) {
                 warn(my $msg = "recv_cmd failed: $!");
                 return send($sock, $msg, MSG_EOR);
         } else {
-                return;
+                my $i = 0;
+                for my $fd (@fds) {
+                        open($self->{$i++}, '+<&=', $fd) and next;
+                        send($sock, "open(+<&=$fd) (FD=$i): $!", MSG_EOR);
+                }
+                return if scalar(@fds) != 4;
         }
         $self->{2}->autoflush(1); # keep stdout buffered until x_it|DESTROY
         # $ENV_STR = join('', map { "\0$_=$ENV{$_}" } keys %ENV);