EvalServer/Child.pm

filter: Statementstmt 23.0% 30 / 130 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 66 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 50.0% 10 / 20 Podpod 100% 2 / 2 totaltotal 14.5% 42 / 288 CC 47 SCAR 52.7
CC
47
Cov
12%
_be_safe
342.0
_be_safe
342.0
run
42.0
CRAP 194.8
↑ Summary EvalServer/Language/Lua.pm »
1 package App::EvalServer::Child;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $App::EvalServer::Child::AUTHORITY = 'cpan:HINRIK';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $App::EvalServer::Child::VERSION = '0.08';
7 }
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use BSD::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use POE::Filter::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use POSIX qw<setgid>;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # we need to load these here, otherwise they'll be loaded on demand
16 # after the chroot, which will fail
17 1 getrusage();
18 1 ▶use Carp::Heavy;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Storable 'nfreeze'; nfreeze([]);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Glob;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 my $PIPE;
23 my $FILTER;
24  
25 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
26 0 ▶ my ($tempdir, $pipe_name, $jail, $user, $limit, $lang, $code, $unsafe)
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
27 = @ARGV;
28  
29 0 ▶ open $PIPE, '>', $pipe_name or die "Can't open $pipe_name: $!";
Branch: 2 branches
BranchTrueFalseTotal
open $PIPE, ">", $pipe_name or die "Can't open ${pipe_name}: $!" 0 0 0
open $PIPE, ">", $pipe_name or die "Can't open ${pipe_name}: $!" 0 0 0
30 0 $FILTER = POE::Filter::Reference->new();
31  
32 # _Inline directories and such will end up here
33 0 ▶ chdir $tempdir or _fail("Can't chdir $tempdir: $!");
Branch: 2 branches
BranchTrueFalseTotal
chdir $tempdir or _fail("Can't chdir ${tempdir}: $!") 0 0 0
chdir $tempdir or _fail("Can't chdir ${tempdir}: $!") 0 0 0
34  
35 0 my $class = "App::EvalServer::Language::$lang";
36 0 eval "require $class";
37 0 chomp $@;
38 0 ▶ _fail($@) if $@;
Branch: 2 branches
BranchTrueFalseTotal
if $@ 0 0 0
if $@ 0 0 0
39  
40 0 ▶ _be_safe($jail, $user, $limit) if !$unsafe;
Branch: 2 branches
BranchTrueFalseTotal
unless $unsafe 0 0 0
unless $unsafe 0 0 0
41  
42 # is this the best approach?
43 0 for my $signal (qw<XFSZ XCPU SEGV>) {
44 0 ▶ $SIG{$signal} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 ▶ _fail('Got a fatal signal', { signal => $signal });
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 };
47 }
48  
49 0 my $result = $class->evaluate($code);
50 0 my ($user_time, $sys_time, $memory) = _usage();
51 0 my $return = {
52 result => $result,
53 user_time => $user_time,
54 sys_time => $sys_time,
55 memory => $memory,
56 };
57  
58 0 print $PIPE $FILTER->put([$return])->[0];
59 0 exit;
60 }
61  
62 0 ▶sub _usage {
Subroutine _usage: not called CC=1 SCAR=6.9
63 0 ▶ my $self_usage = [getrusage(RUSAGE_SELF)];
Subroutine _usage: not called CC=1 SCAR=6.9
64 0 my $child_usage = [getrusage(RUSAGE_CHILDREN)];
65 0 my $user_time = $self_usage->[0];
66 0 my $sys_time = $self_usage->[1];
67 0 my $memory = $self_usage->[2] + $child_usage->[2];
68  
69 0 return ($user_time, $sys_time, $memory);
70 }
71  
72 0 ▶sub _fail {
Subroutine _fail: not called CC=2 SCAR=17.9
73 0 ▶ my ($error, $return) = @_;
Subroutine _fail: not called CC=2 SCAR=17.9
74 0 ▶ $return = { } if ref $return ne 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $return ne "HASH" 0 0 0
if ref $return ne "HASH" 0 0 0
75  
76 0 $return->{error} = $error;
77 0 my ($user_time, $sys_time, $memory) = _usage();
78 0 $return->{user_time} = $user_time;
79 0 $return->{sys_time} = $sys_time;
80 0 $return->{memory} = $memory;
81  
82 0 print $PIPE $FILTER->put([$return])->[0];
83 0 exit;
84 }
85  
86 0 ▶sub _be_safe {
Subroutine _be_safe: not called CC=18 SCAR=58.3
87 0 ▶ my ($jail, $user, $limit) = @_;
Subroutine _be_safe: not called CC=18 SCAR=58.3
88  
89 0 my $new_uid = getpwnam($user);
90 0 ▶ _fail("Can't find uid for '$user'") if !defined $new_uid;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $new_uid 0 0 0
unless defined $new_uid 0 0 0
91
92 # Set the CPU LIMIT.
93 # Do this before the chroot because some of the other
94 # setrlimit calls will prevent chroot from working
95 # however at the same time we need to preload an autload file
96 # that chroot will prevent, so do it here.
97 0 setrlimit(RLIMIT_CPU, 10, 10);
98  
99 0 ▶ _fail("Not root, can't chroot or take other precautions, dying") if $< != 0;
Branch: 2 branches
BranchTrueFalseTotal
if $< != 0 0 0 0
if $< != 0 0 0 0
100  
101 0 ▶ chdir or _fail("Failed to chdir into $jail: $!");
Branch: 2 branches
BranchTrueFalseTotal
chdir or _fail("Failed to chdir into ${jail}: $!") 0 0 0
chdir or _fail("Failed to chdir into ${jail}: $!") 0 0 0
102 0 ▶ chroot '.' or _fail("Failed to chroot into $jail: $!");
Branch: 2 branches
BranchTrueFalseTotal
chroot "." or _fail("Failed to chroot into ${jail}: $!") 0 0 0
chroot "." or _fail("Failed to chroot into ${jail}: $!") 0 0 0
103  
104 # drop root privileges
105 0 $)="$new_uid $new_uid";
106 0 $(=$new_uid;
107 0 $<=$>=$new_uid;
108 0 setgid($new_uid); #We just assume the uid is the same as the gid. Hot.
109  
110 0 ▶ if ($> != $new_uid || $< != $new_uid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($> != $new_uid or $< != $new_uid) 0 0 0
if ($> != $new_uid or $< != $new_uid) 0 0 0
Condition0%0/6
$> != $new_uid or $< != $new_uid
l!l&&r!l&&!r
000
$> != $new_uid or $< != $new_uid
l!l&&r!l&&!r
000
MC/DC0%0/2
$> != $new_uid or $< != $new_uid
$> != $new_uid $< != $new_uid
MC/DC0%0/2
$> != $new_uid or $< != $new_uid
$> != $new_uid $< != $new_uid
Truth table0%0/3
A or B
A= $> != $new_uidB= $< != $new_uid
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $> != $new_uidB= $< != $new_uid
ABresult
1X1
011
000
111 0 _fail("Failed to drop root privileges");
112 }
113  
114 0 my $kilo = 1024;
115 0 my $meg = $kilo * $kilo;
116 0 my $limit_bytes = $limit * $meg;
117  
118 (
119 0 ▶ setrlimit(RLIMIT_DATA, $limit_bytes, $limit_bytes)
Branch: 2 branches
BranchTrueFalseTotal
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) and &setrlimit(scalar RLIMIT_CPU(), 10, 10) or _fail("Failed to set resource limits: $!") 0 0 0
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) and &setrlimit(scalar RLIMIT_CPU(), 10, 10) or _fail("Failed to set resource limits: $!") 0 0 0
Condition0%0/60
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) and &setrlimit(scalar RLIMIT_CPU(), 10, 10)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) and &setrlimit(scalar RLIMIT_CPU(), 10, 10)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1)
!ll&&!rl&&r
000
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes)
!ll&&!rl&&r
000
MC/DC0%0/11
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) and &setrlimit(scalar RLIMIT_CPU(), 10, 10)
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_NPROC(), 1, 1) &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) &setrlimit(scalar RLIMIT_OFILE(), 0, 0) &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) &setrlimit(scalar RLIMIT_CPU(), 10, 10)
MC/DC0%0/11
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_NPROC(), 1, 1) and &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OFILE(), 0, 0) and &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) and &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) and &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) and &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) and &setrlimit(scalar RLIMIT_CPU(), 10, 10)
&setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_NPROC(), 1, 1) &setrlimit(scalar RLIMIT_NOFILE(), 0, 0) &setrlimit(scalar RLIMIT_OFILE(), 0, 0) &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0) &setrlimit(scalar RLIMIT_LOCKS(), 0, 0) &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes) &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100) &setrlimit(scalar RLIMIT_CPU(), 10, 10)
Truth table0%0/12
A and B and C and D and E and F and G and H and I and J and K
A= &setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes)B= &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes)C= &setrlimit(scalar RLIMIT_NPROC(), 1, 1)D= &setrlimit(scalar RLIMIT_NOFILE(), 0, 0)E= &setrlimit(scalar RLIMIT_OFILE(), 0, 0)F= &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0)G= &setrlimit(scalar RLIMIT_LOCKS(), 0, 0)H= &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes)I= &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes)J= &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100)K= &setrlimit(scalar RLIMIT_CPU(), 10, 10)
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XXXXXXX0
11110XXXXXX0
111110XXXXX0
1111110XXXX0
11111110XXX0
111111110XX0
1111111110X0
111111111100
111111111111
Truth table0%0/12
A and B and C and D and E and F and G and H and I and J and K
A= &setrlimit(scalar RLIMIT_DATA(), $limit_bytes, $limit_bytes)B= &setrlimit(scalar RLIMIT_STACK(), $limit_bytes, $limit_bytes)C= &setrlimit(scalar RLIMIT_NPROC(), 1, 1)D= &setrlimit(scalar RLIMIT_NOFILE(), 0, 0)E= &setrlimit(scalar RLIMIT_OFILE(), 0, 0)F= &setrlimit(scalar RLIMIT_OPEN_MAX(), 0, 0)G= &setrlimit(scalar RLIMIT_LOCKS(), 0, 0)H= &setrlimit(scalar RLIMIT_AS(), $limit_bytes, $limit_bytes)I= &setrlimit(scalar RLIMIT_VMEM(), $limit_bytes, $limit_bytes)J= &setrlimit(scalar RLIMIT_MEMLOCK(), 100, 100)K= &setrlimit(scalar RLIMIT_CPU(), 10, 10)
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XXXXXXX0
11110XXXXXX0
111110XXXXX0
1111110XXXX0
11111110XXX0
111111110XX0
1111111110X0
111111111100
111111111111
120 and
121 setrlimit(RLIMIT_STACK, $limit_bytes, $limit_bytes)
122 and
123 setrlimit(RLIMIT_NPROC, 1, 1)
124 and
125 setrlimit(RLIMIT_NOFILE, 0, 0)
126 and
127 setrlimit(RLIMIT_OFILE, 0, 0)
128 and
129 setrlimit(RLIMIT_OPEN_MAX, 0, 0)
130 and
131 setrlimit(RLIMIT_LOCKS, 0, 0)
132 and
133 setrlimit(RLIMIT_AS, $limit_bytes, $limit_bytes)
134 and
135 setrlimit(RLIMIT_VMEM, $limit_bytes, $limit_bytes)
136 and
137 setrlimit(RLIMIT_MEMLOCK, 100, 100)
138 and
139 setrlimit(RLIMIT_CPU, 10, 10)
140 )
141 or _fail("Failed to set resource limits: $!");
142  
143 #setrlimit(RLIMIT_MSGQUEUE,100,100);
144 0 return;
145 }
146  
147 1 1;
148  
149 =encoding utf8
150  
151 =head1 NAME
152  
153 App::EvalServer::Child - Evaluate code in a safe child process
154  
155 =head1 SYNOPSIS
156  
157 # fork, etc
158  
159 use App::EvalServer::Child;
160 App::EvalServer::Child::run(
161 $tempdir, $pipe_name, $jail, $user, $limit, $lang, $code, $unsafe,
162 );
163  
164 =head1 DESCRIPTION
165  
166 This module takes various safety precautions, then executes the code you
167 provided.
168  
169 =head1 FUNCTIONS
170  
171 =head2 C<run>
172  
173 Runs the code. Takes the following arguments: a temporary directory, a pipe
174 name, a jail path, a username, a process limit (in megabytes), a language
175 suffix (e.g. 'Perl' for C<App::EvalServer::Language::Perl>), the code, and
176 an unsafe flag. If the unsafe flag is on, C<run> will not take safety
177 precautions (change user, chroot, set resource limits) which require root
178 access.
179  
180 =head1 AUTHOR
181  
182 Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
183  
184 =head1 LICENSE AND COPYRIGHT
185  
186 Copyright 2010 Hinrik E<Ouml>rn SigurE<eth>sson
187  
188 This program is free software, you can redistribute it and/or modify
189 it under the same terms as Perl itself.
190  
191 =cut
↑ Summary EvalServer/Language/Lua.pm »