line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SmokeRunner::Multi::SafeRun; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
9
|
|
|
9
|
|
327
|
$SmokeRunner::Multi::SafeRun::AUTHORITY = 'cpan:YANICK'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$SmokeRunner::Multi::SafeRun::VERSION = '0.19'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
#ABSTRACT: Run an external command safely in taint mode |
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
53
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
287
|
|
11
|
9
|
|
|
9
|
|
49
|
use warnings; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
341
|
|
12
|
|
|
|
|
|
|
|
13
|
9
|
|
|
9
|
|
51
|
use base 'Exporter'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
1130
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = 'safe_run'; |
16
|
|
|
|
|
|
|
|
17
|
9
|
|
|
9
|
|
50
|
use Cwd qw( abs_path ); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
447
|
|
18
|
9
|
|
|
9
|
|
49
|
use File::Spec; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
1595
|
|
19
|
9
|
|
|
9
|
|
1001
|
use File::Which qw( which ); |
|
9
|
|
|
|
|
1252
|
|
|
9
|
|
|
|
|
509
|
|
20
|
|
|
|
|
|
|
use SmokeRunner::Multi::Validate |
21
|
9
|
|
|
9
|
|
55
|
qw( validate SCALAR_TYPE ARRAYREF_TYPE SCALARREF_TYPE ); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
96
|
|
22
|
9
|
|
|
9
|
|
18093
|
use IPC::Run3 qw( run3 ); |
|
9
|
|
|
|
|
238400
|
|
|
9
|
|
|
|
|
2572
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
my $spec = { command => SCALAR_TYPE, |
27
|
|
|
|
|
|
|
args => ARRAYREF_TYPE( default => [] ), |
28
|
|
|
|
|
|
|
stdout_buffer => SCALARREF_TYPE, |
29
|
|
|
|
|
|
|
stderr_buffer => SCALARREF_TYPE, |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub safe_run |
33
|
|
|
|
|
|
|
{ |
34
|
7
|
|
|
7
|
1
|
3856
|
my %p = validate( @_, $spec ); |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
|
|
47
|
my $cmd; |
37
|
7
|
100
|
|
|
|
142
|
if ( File::Spec->file_name_is_absolute( $p{command} ) ) |
38
|
|
|
|
|
|
|
{ |
39
|
4
|
|
|
|
|
9
|
$cmd = $p{command}; |
40
|
|
|
|
|
|
|
|
41
|
4
|
50
|
|
|
|
163
|
die "$cmd is not executable" |
42
|
|
|
|
|
|
|
unless -x $cmd; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else |
45
|
|
|
|
|
|
|
{ |
46
|
3
|
50
|
|
|
|
23
|
$cmd = which( $p{command} ) |
47
|
|
|
|
|
|
|
or die "Cannot find $p{command} in path"; |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
727
|
$cmd = abs_path($cmd); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# This is a simple way to make the path taint-safe. |
53
|
7
|
|
|
|
|
63
|
local $ENV{PATH} = ''; |
54
|
7
|
|
|
|
|
17
|
run3( [ $cmd, @{ $p{args} } ], |
|
7
|
|
|
|
|
60
|
|
55
|
|
|
|
|
|
|
undef, |
56
|
|
|
|
|
|
|
$p{stdout_buffer}, $p{stderr_buffer} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |