about summary refs log tree commit homepage
path: root/t/spawn.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-02-25 05:14:10 +0000
committerEric Wong <e@80x24.org>2019-04-04 09:13:58 +0000
commit721368cd04bfbd03c0d9173fff633ae34f16409a (patch)
tree8b4f8fc9eb232c551f9f3455de8bb4aea0e35712 /t/spawn.t
parent293c51d2c23ceb8b8018cf4bfa3deaf56f7753b2 (diff)
downloadpublic-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/spawn.t')
-rw-r--r--t/spawn.t18
1 files changed, 18 insertions, 0 deletions
diff --git a/t/spawn.t b/t/spawn.t
index db3f2dc9..5abedc96 100644
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -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;