| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $ENV{'SHELL'} = $shell if defined $shell; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | $CGI::POST_MAX = $args{'POST_MAX'} if exists $args{'POST_MAX'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | $ENV{'PATH'} = $args{'PATH'} if exists $args{'PATH'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | $ENV{'SHELL'} = $args{'SHELL'} if exists $args{'SHELL'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | return CGI::new( $class, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | ( exists $args{'source'} ? $args{'source'} : () ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $args{"DISABLE_UPLOADS"} and defined $args{"DISABLE_UPLOADS"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
exists $args{"POST_MAX"} and defined $args{"POST_MAX"} and $args{"POST_MAX"} =~ /^\d+$/
exists $args{"POST_MAX"} and defined $args{"POST_MAX"}
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+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||