diff options
author | Eric Wong <e@80x24.org> | 2019-02-25 05:14:10 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-04-04 09:13:58 +0000 |
commit | 721368cd04bfbd03c0d9173fff633ae34f16409a (patch) | |
tree | 8b4f8fc9eb232c551f9f3455de8bb4aea0e35712 /t | |
parent | 293c51d2c23ceb8b8018cf4bfa3deaf56f7753b2 (diff) | |
download | public-inbox-721368cd04bfbd03c0d9173fff633ae34f16409a.tar.gz |
We'll be spawning cgit and git-diff, which can take gigantic amounts of CPU time and/or heap given the right (ermm... wrong) input. Limit the damage that large/expensive diffs can cause.
Diffstat (limited to 't')
-rw-r--r-- | t/spawn.t | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -92,6 +92,24 @@ use PublicInbox::Spawn qw(which spawn popen_rd); isnt($?, 0, '$? set properly: '.$?); } +SKIP: { + eval { + require BSD::Resource; + defined(BSD::Resource::RLIMIT_CPU()) + } or skip 'BSD::Resource::RLIMIT_CPU missing', 3; + my ($r, $w); + pipe($r, $w) or die "pipe: $!"; + my $cmd = ['sh', '-c', 'while true; do :; done']; + my $opt = { RLIMIT_CPU => [ 1, 1 ], RLIMIT_CORE => 0, 1 => fileno($w) }; + my $pid = spawn($cmd, undef, $opt); + close $w or die "close(w): $!"; + my $rset = ''; + vec($rset, fileno($r), 1) = 1; + ok(select($rset, undef, undef, 5), 'child died before timeout'); + is(waitpid($pid, 0), $pid, 'XCPU child process reaped'); + isnt($?, 0, 'non-zero exit status'); +} + done_testing(); 1; |