blib/lib/CGI/Safe.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 70.8% 17 / 24 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 84.6% 11 / 13 Podpod 100% 4 / 4 totaltotal 85.9% 104 / 121 CC 16 SCAR 15.2
CC
16
Cov
88%
new
7.1
set
6.2
import
6.0
CRAP 4.6
↑ Summary
1 ################################
2 package CGI::Safe;
3 ################################
4 5 $VERSION = 1.25;
5  
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use vars qw/ @ISA /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 @ISA = qw/ CGI /;
12  
13 5 ▶use vars qw/ $shell $path /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Clean up the environment and establish some defaults
18 5 $shell = $ENV{'SHELL'};
19 5 $path = $ENV{'PATH'};
20 5 delete @ENV{qw/ IFS CDPATH ENV BASH_ENV PATH SHELL /};
21 5 $CGI::DISABLE_UPLOADS = 1; # Disable uploads
22 5 $CGI::POST_MAX = 512 * 1024; # limit posts to 512K max
23 }
24  
25 4 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
26 4 ▶ if ( grep { /:(?:standard|cgi)/ } @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/:(?:standard|cgi)/;} @_) 2 2 4
27 2 my $set_sub = caller(0) . '::set';
28 2 my $shell_sub = caller(0) . '::get_shell';
29 2 my $path_sub = caller(0) . '::get_path';
30 {
31 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 *{$set_sub} = \&set;
33 2 *{$shell_sub} = \&get_shell;
34 2 *{$path_sub} = \&get_path;
35 }
36 }
37  
38 4 my $index;
39  
40 # restore untainted path and shell if the list 'admin' in import list
41 4 my %args = map { $_ => 1 } @_[ 1 .. $#_ ];
42  
43 4 ▶ if ( exists $args{'admin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"admin"}) 2 2 4
44  
45 # If 'admin' is specified, we'll reset the PATH and SHELL. These will still
46 # be tainted and require untainting by the CGI program.
47 2 ▶ $ENV{'PATH'} = $path if defined $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $CGI::Safe::path 2 0 2
48 2 ▶ $ENV{'SHELL'} = $shell if defined $shell;
Branch: 1 branch
BranchTrueFalseTotal
if defined $CGI::Safe::shell 0 2 2
49 2 delete $args{'admin'};
50 2 splice @_, 1, $#_, keys %args;
51 }
52  
53 # TODO: Future releases will allow untainting to occur at the time that CGI
54 # data is grabbed. We include this so that people will know that future
55 # versions will require 'taint' in the import list to allow their scripts to
56 # run with minimal changes
57 4 ▶ if ( exists $args{'taint'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"taint"}) 1 3 4
58 1 delete $args{'taint'};
59 1 splice @_, 1, $#_, keys %args;
60 }
61  
62 # using goto to avoid updating caller
63 4 goto &CGI::import;
64 }
65  
66 2 ▶sub new {
Subroutine new: called CC=6 SCAR=19.6
Pod documented
67 2 my ( $class, %args ) = @_;
68 $CGI::DISABLE_UPLOADS = $args{'DISABLE_UPLOADS'}
69 2 ▶ if exists $args{'DISABLE_UPLOADS'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"DISABLE_UPLOADS"} 0 2 2
70 2 ▶ $CGI::POST_MAX = $args{'POST_MAX'} if exists $args{'POST_MAX'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"POST_MAX"} 0 2 2
71 2 ▶ $ENV{'PATH'} = $args{'PATH'} if exists $args{'PATH'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"PATH"} 0 2 2
72 2 ▶ $ENV{'SHELL'} = $args{'SHELL'} if exists $args{'SHELL'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"SHELL"} 0 2 2
73  
74 return CGI::new( $class,
75 2 ▶ ( exists $args{'source'} ? $args{'source'} : () ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'source'} ? : 2 0 2
76 }
77  
78 8 ▶sub set {
Subroutine set: called CC=6 SCAR=18.2
Pod documented
79 8 my ( $self, %args ) = CGI::self_or_default(@_);
80 8 ▶ if ( exists $args{'DISABLE_UPLOADS'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"DISABLE_UPLOADS"} and defined $args{"DISABLE_UPLOADS"}) 4 4 8
Condition66%2/3
exists $args{"DISABLE_UPLOADS"} and defined $args{"DISABLE_UPLOADS"}
!ll&&!rl&&r
404
MC/DC50%1/2
exists $args{"DISABLE_UPLOADS"} and defined $args{"DISABLE_UPLOADS"}
exists $args{"DISABLE_UPLOADS"} defined $args{"DISABLE_UPLOADS"}
Truth table66%2/3
A and B
A= exists $args{"DISABLE_UPLOADS"}B= defined $args{"DISABLE_UPLOADS"}
ABresult
0X0
100
111
81 and defined $args{'DISABLE_UPLOADS'} )
82 {
83 4 $CGI::DISABLE_UPLOADS = $args{'DISABLE_UPLOADS'};
84 }
85 8 ▶ if ( exists $args{'POST_MAX'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"POST_MAX"} and defined $args{"POST_MAX"} and $args{"POST_MAX"} =~ /^\d+$/) 4 4 8
Condition66%4/6
exists $args{"POST_MAX"} and defined $args{"POST_MAX"} and $args{"POST_MAX"} =~ /^\d+$/
!ll&&!rl&&r
404
exists $args{"POST_MAX"} and defined $args{"POST_MAX"}
!ll&&!rl&&r
404
MC/DC33%1/3
exists $args{"POST_MAX"} and defined $args{"POST_MAX"} and $args{"POST_MAX"} =~ /^\d+$/
exists $args{"POST_MAX"} defined $args{"POST_MAX"} $args{"POST_MAX"} =~ /^\d+$/
Truth table50%2/4
A and B and C
A= exists $args{"POST_MAX"}B= defined $args{"POST_MAX"}C= $args{"POST_MAX"} =~ /^\d+$/
ABCresult
0XX0
10X0
1100
1111
86 and defined $args{'POST_MAX'}
87 and $args{'POST_MAX'} =~ /^\d+$/ )
88 {
89 4 $CGI::POST_MAX = $args{'POST_MAX'};
90 }
91 }
92  
93 0 ▶sub get_path { $path }
Subroutine get_path: not called CC=1 SCAR=6.9
Pod documented
94  
95 0 ▶sub get_shell { $shell }
Subroutine get_shell: not called CC=1 SCAR=6.9
Pod documented
96  
97 5 "Ovid";
98  
99 __END__
↑ Summary