user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 13/13] spawnpp: raise exception on E2BIG errors
Date: Sun,  7 Feb 2021 23:05:21 -1000	[thread overview]
Message-ID: <20210208090521.28909-14-e@80x24.org> (raw)
In-Reply-To: <20210208090521.28909-1-e@80x24.org>

This matches the Inline::C version, and lets us test
argv overflow with $search->query_argv_to_string;
---
 lib/PublicInbox/SpawnPP.pm | 23 +++++++++++++++++++----
 t/search.t                 |  7 +++++++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index 2c5edef6..6d7e2c34 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -16,13 +16,19 @@ sub pi_fork_exec ($$$$$$$) {
 	$set->fillset or die "fillset failed: $!";
 	sigprocmask(SIG_SETMASK, $set, $old) or die "can't block signals: $!";
 	my $syserr;
+	pipe(my ($r, $w));
 	my $pid = fork;
 	unless (defined $pid) { # compat with Inline::C version
 		$syserr = $!;
 		$pid = -1;
 	}
 	if ($pid == 0) {
-		$SIG{__DIE__} = sub { warn @_; _exit 1 };
+		close $r;
+		$SIG{__DIE__} = sub {
+			warn(@_);
+			syswrite($w, my $num = $! + 0);
+			_exit(1);
+		};
 		for my $child_fd (0..$#$redir) {
 			my $parent_fd = $redir->[$child_fd];
 			next if $parent_fd == $child_fd;
@@ -32,7 +38,9 @@ sub pi_fork_exec ($$$$$$$) {
 		if ($pgid >= 0 && !defined(setpgid(0, $pgid))) {
 			die "setpgid(0, $pgid): $!";
 		}
-		$SIG{$_} = 'DEFAULT' for keys %SIG;
+		for (keys %SIG) {
+			$SIG{$_} = 'DEFAULT' if substr($_, 0, 1) ne '_';
+		}
 		if ($cd ne '') {
 			chdir $cd or die "chdir $cd: $!";
 		}
@@ -49,11 +57,18 @@ sub pi_fork_exec ($$$$$$$) {
 		} else {
 			%ENV = map { split(/=/, $_, 2) } @$env;
 		}
-		exec @$cmd;
+		undef $r;
+		exec { $f } @$cmd;
 		die "exec @$cmd failed: $!";
 	}
+	close $w;
 	sigprocmask(SIG_SETMASK, $old) or die "can't unblock signals: $!";
-	$! = $syserr;
+	if (my $cerrnum = do { local $/, <$r> }) {
+		$pid = -1;
+		$! = $cerrnum;
+	} else {
+		$! = $syserr;
+	}
 	$pid;
 }
 
diff --git a/t/search.t b/t/search.t
index 56c7db1c..36a8fb30 100644
--- a/t/search.t
+++ b/t/search.t
@@ -576,6 +576,13 @@ SKIP: {
 	$q = $s->query_argv_to_string($g, [qw{OR (rt:1993-10-02)}]);
 	like($q, qr/\AOR \(rt:749\d{6}\.\.749\d{6}\)\z/,
 		'trailing parentheses preserved');
+	$ENV{TEST_EXPENSIVE} or
+		skip 'TEST_EXPENSIVE not set for argv overflow check', 1;
+	my @w;
+	local $SIG{__WARN__} = sub { push @w, @_ }; # for pure Perl version
+	my @fail = map { 'd:1993-10-02..2010-10-02' } (1..(4096 * 32));
+	eval { $s->query_argv_to_string($g, \@fail) };
+	ok($@, 'exception raised');
 }
 
 done_testing();

      parent reply	other threads:[~2021-02-08  9:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08  9:05 [PATCH 00/13] lei approxidate, startup fix, --alert Eric Wong
2021-02-08  9:05 ` [PATCHv2 01/13] lei q: improve remote mboxrd UX + MUA Eric Wong
2021-02-08  9:05 ` [PATCH 02/13] lei_xsearch: quiet Eml warnings from remote mboxrds Eric Wong
2021-02-08  9:05 ` [PATCH 03/13] lei q: SIGWINCH process group with the terminal Eric Wong
2021-02-08  9:05 ` [PATCH 04/13] lei q: support --alert=CMD for early MUA users Eric Wong
2021-02-08  9:05 ` [PATCH 05/13] tests: favor IPv6 Eric Wong
2021-02-08  9:05 ` [PATCH 06/13] ds: improve add_timer usability Eric Wong
2021-02-08  9:05 ` [PATCH 07/13] lei: start_pager: drop COLUMNS default Eric Wong
2021-02-08  9:05 ` [PATCH 08/13] lei: avoid racing on unlink + bind + listen Eric Wong
2021-02-08  9:05 ` [PATCH 09/13] lei: drop BSD::Resource usage Eric Wong
2021-02-08  9:05 ` [PATCH 10/13] git: implement date_parse method Eric Wong
2021-02-08  9:05 ` [PATCH 11/13] lei q: use git approxidate with d:, dt: and rt: ranges Eric Wong
2021-02-10  9:59   ` [PATCH] search: fix argv handling of quoted phrases Eric Wong
2021-02-08  9:05 ` [PATCH 12/13] search: use one git-rev-parse process for all dates Eric Wong
2021-02-08  9:05 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210208090521.28909-14-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 13/13] spawnpp: raise exception on E2BIG errors' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this 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).