| 1 | package CGI::PSGI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | our $VERSION = '0.17'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use base qw(CGI); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 37 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 37 | my($class, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 37 | CGI::initialize_globals(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 37 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | psgi_env => $env, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | use_tempfile => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 37 | local *ENV = $env; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 37 | local $CGI::MOD_PERL = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # never fall back to CGI.pm's offline debugging mode, which reads the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # params from the process' own @ARGV: older CGI.pm does that for any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # unrecognised REQUEST_METHOD, e.g. OPTIONS (CVE-2026-120637), and all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # versions do it for an env without one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 37 | local $CGI::DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 37 | $self->SUPER::init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 37 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
env: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $_[0]->{psgi_env}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # CGI.pm expects read() on STDIN semantics: the full $len bytes unless EOF or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # an error. psgi.input->read may return fewer (like sysread), so keep reading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # until $len, EOF (0) or an error (undef). Returns the number of bytes read, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # or the 0/undef of the first read if nothing was read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | ▶ | sub read_from_client { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_from_client: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 25 | my($self, $buff, $len, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 25 | my $input = $self->{psgi_env}{'psgi.input'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 25 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$offset ||= 0
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 25 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 25 | ▶ | while ($total < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8371 | my $read = $input->read($$buff, $len - $total, $offset + $total); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 8371 | ▶ | return $total || $read unless $read; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$total || $read
MC/DC50%1/2
$total || $read
$total
$read
Truth table66%2/3
A || B
A= $totalB= $read
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8367 | $total += $read; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 21 | return $total; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # copied from CGI.pm. Deprecated: no CGI.pm since (at least) 4.04 calls it, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # and it will be removed in a future release. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub read_from_stdin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_from_stdin: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my($self, $buff) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my($eoffound) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my($localbuf) = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my($tempbuf) = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my($bufsiz) = 1024; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | while ($eoffound == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $res = $self->{psgi_env}{'psgi.input'}->read($tempbuf, $bufsiz, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( !defined($res) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # TODO: how to do error reporting ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $eoffound = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( $res == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $eoffound = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $localbuf .= $tempbuf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $$buff = $localbuf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Like CGI::Util::_rearrange_params (private to CGI.pm, so not used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # directly): maps -named or positional arguments onto the slots in $order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # and returns the slots, plus a hash ref of the leftover named arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 88 | ▶ | sub _rearrange_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rearrange_params: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 88 | my($order, @param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 88 | ▶ | return [] unless @param; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 87 | ▶ | if (ref($param[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | @param = %{$param[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | return \@param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 87 | ▶ | unless defined($param[0]) && substr($param[0],0,1) eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $param[0] and substr($param[0], 0, 1) eq "-"
MC/DC50%1/2
defined $param[0] and substr($param[0], 0, 1) eq "-"
defined $param[0]
substr($param[0], 0, 1) eq "-"
Truth table66%2/3
A and B
A= defined $param[0]B= substr($param[0], 0, 1) eq "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 55 | my(%pos, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 55 | $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 55 | for my $slot (@$order) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 451 | ▶ | $pos{lc $_} = $i for ref($slot) eq 'ARRAY' ? @$slot : $slot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 451 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 55 | my %params = @param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 55 | my(@result, %leftover); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 55 | $#result = $#$order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # favour CONTENT-TYPE over TYPE etc. when both are given, as CGI.pm does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # (same comparator as CGI.pm, for compatibility) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 55 | ▶ | for my $k (sort { $a =~ /content/i ? 1 : $b =~ /content/i ? -1 : $a cmp $b } keys %params) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 129 | (my $key = lc $k) =~ s/^-//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 129 | ▶ | if (exists $pos{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 94 | $result[$pos{$key}] = $params{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 35 | $leftover{$key} = $params{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 55 | return \@result, \%leftover; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Unfold CRLF + whitespace (RFC 822) in place, and die on any other newline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 138 | ▶ | sub _check_header_values { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_header_values: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 138 | for my $header (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 623 | ▶ | next unless defined $header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 339 | $header =~ s/$CGI::CRLF(\s)/$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 339 | ▶ | if ($header =~ m/$CGI::CRLF|\015|\012/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # shorten very long values in the diagnostic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 17 | ▶ | $header = substr($header,0,72).'...' if length $header > 72; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 17 | die "Invalid header value contains a newline not followed by whitespace: $header"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Ported from CGI::header. Values are used as given: like CGI.pm 5.02 they are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # no longer HTML unescaped, which decoded entities such as after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # the newline check (CVE-2026-120639). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 72 | ▶ | sub psgi_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
psgi_header: called CC=32 SCAR=34.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 72 | my($self, @p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 72 | my(@header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 72 | my $order = [['TYPE','CONTENT_TYPE','CONTENT-TYPE'], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 'STATUS',['COOKIE','COOKIES','SET-COOKIE'],'TARGET', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 'EXPIRES','NPH','CHARSET', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 'ATTACHMENT','P3P']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 72 | my($result, $leftover) = _rearrange_params($order, @p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | my($type,$status,$cookie,$target,$expires,$nph,$charset,$attachment,$p3p) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 72 | @{$result}[0 .. $#$order]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # extra headers: positional ones given as name=value or as a ready-made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # "Name: value" line (which CGI.pm 5.02 sends as it is), and leftover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # named ones, where -x_foo => 'bar' becomes X-foo: bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 72 | my @other_headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 72 | my @lines = grep defined, @{$result}[@$order .. $#$result]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # check the whole lines first, so a newline anywhere in one dies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # rather than the line being skipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 72 | _check_header_values(@lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 66 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # Don't use \s because of perl bug 21951 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 23 | ▶ | if (my($name, $value) = $line =~ /([^ \r\n\t=]+)=\"?(.+?)\"?$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | push @other_headers, ucfirst(lc $name), $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } elsif (($name, $value) = $line =~ /^([!#\$%&'*+.^_`|~0-9A-Za-z-]+):[ \t]*(.*?)[ \t]*$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # CGI.pm ucfirsts the whole line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 13 | push @other_headers, ucfirst($name), $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # anything else (no colon, or not a valid header name) can't be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # made a header, and is skipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 66 | ▶ | for my $name (sort keys %{ $leftover || {} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$leftover || {}
MC/DC100%1/1
$leftover || {}
$leftover
Truth table100%2/2
A
A= $leftover
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 28 | ▶ | next unless defined $leftover->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 28 | (my $header = lc $name) =~ tr/_/-/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 28 | push @other_headers, ucfirst($header), "$leftover->{$name}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # Since $cookie and $p3p may be array references, stringify them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # before the newline checks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 66 | my @cookie; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 66 | ▶ | for (ref($cookie) eq 'ARRAY' ? @$cookie : $cookie) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 66 | ▶ | my $cs = UNIVERSAL::isa($_,'CGI::Cookie') ? $_->as_string : $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 66 | ▶ | push @cookie, $cs if defined $cs and $cs ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cs and $cs ne ""
MC/DC100%2/2
defined $cs and $cs ne ""
defined $cs
$cs ne ""
Truth table100%3/3
A and B
A= defined $csB= $cs ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 66 | ▶ | $p3p = join(" ", @$p3p) if ref($p3p) eq "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # header names and values, per RFC 822 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 66 | _check_header_values($type,$status,@cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other_headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 55 | ▶ | $type ||= 'text/html' unless defined($type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$type ||= "text/html"
MC/DC0%0/1
$type ||= "text/html"
$type
Truth table50%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 55 | ▶ | if (defined $charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 22 | $self->charset($charset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 33 | ▶ | $charset = $self->charset if $type =~ /^text\//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 55 | ▶ | $charset ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$charset ||= ""
MC/DC100%1/1
$charset ||= ""
$charset
Truth table100%2/2
A
A= $charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 55 | ▶ | $type .= "; charset=$charset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$type ne "" and not $type =~ /\bcharset\b/ and defined $charset and $charset ne ""
$type ne "" and not $type =~ /\bcharset\b/ and defined $charset
$type ne "" and not $type =~ /\bcharset\b/
MC/DC50%2/4
$type ne "" and not $type =~ /\bcharset\b/ and defined $charset and $charset ne ""
$type ne ""
not $type =~ /\bcharset\b/
defined $charset
$charset ne ""
Truth table60%3/5
A and not(B) and C and D
A= $type ne ""B= not $type =~ /\bcharset\b/C= defined $charsetD= $charset ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | if $type ne '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | and $type !~ /\bcharset\b/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | and defined $charset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | and $charset ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 55 | ▶ | push(@header, "Window-Target", $target) if $target; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 55 | ▶ | push(@header, "P3P", qq(policyref="/w3c/p3p.xml", CP="$p3p")) if $p3p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # push all the cookies -- there may be several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 55 | push(@header, map { ("Set-Cookie", $_) } @cookie); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # if the user indicates an expiration time, then we need | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # both an Expires and a Date header (so that the browser is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # uses OUR clock) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 55 | ▶ | push(@header,"Expires", CGI::expires($expires,'http')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | if $expires; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 55 | ▶ | push(@header,"Date", CGI::expires(0,'http')) if $expires || $cookie || $nph; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$expires or $cookie or $nph
$expires or $cookie
MC/DC33%1/3
$expires or $cookie or $nph
$expires
$cookie
$nph
Truth table50%2/4
A or B or C
A= $expiresB= $cookieC= $nph
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 55 | ▶ | push(@header,"Pragma", "no-cache") if $self->cache(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 55 | ▶ | if ($attachment) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # the filename is a quoted-string (RFC 9110 5.6.4), so a " or \ in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # it must be escaped, or it could inject other parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # (CVE-2026-120647) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | (my $filename = $attachment) =~ s/(["\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | push(@header,"Content-Disposition", "attachment; filename=\"$filename\""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 55 | push(@header, @other_headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 55 | ▶ | push(@header,"Content-Type", $type) if $type ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 55 | ▶ | $status ||= "200"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$status ||= 200
MC/DC100%1/1
$status ||= 200
$status
Truth table100%2/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 55 | $status =~ s/\D*$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 55 | return $status, \@header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Ported from CGI.pm's redirect() method. Like CGI.pm 5.02, values are passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # on as given: HTML unescaping them decoded entities in a (possibly app | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # validated) Location, e.g. "//evil.example/" became "//evil.example/" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # (CVE-2026-120638). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 16 | ▶ | sub psgi_redirect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
psgi_redirect: called CC=8 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 16 | my ($self,@p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 16 | my $order = [['LOCATION','URI','URL'],'TARGET','STATUS',['COOKIE','COOKIES','SET-COOKIE'],'NPH']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 16 | my($result, $leftover) = _rearrange_params($order, @p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 16 | my($url,$target,$status,$cookie,$nph,@other) = @$result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 16 | ▶ | $status = '302 Found' unless defined $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 16 | ▶ | $url ||= $self->self_url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$url ||= $self->self_url
MC/DC0%0/2
$url ||= $self->self_url
$url
$self->self_url
Truth table66%2/3
A ||= B
A= $urlB= $self->self_url
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 16 | my(@o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # extra positional parameters, given as name=value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | for (@other) { next unless defined; tr/\"//d; push(@o,split("=",$_,2)); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # extra named parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 16 | ▶ | push(@o, map { ("-$_" => $leftover->{$_}) } sort keys %{ $leftover || {} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$leftover || {}
MC/DC100%1/1
$leftover || {}
$leftover
Truth table100%2/2
A
A= $leftover
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 16 | unshift(@o, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | '-Status' => $status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | '-Location'=> $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | '-nph' => $nph); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 16 | ▶ | unshift(@o,'-Target'=>$target) if $target; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 16 | unshift(@o,'-Type'=>''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 16 | ▶ | unshift(@o,'-Cookie'=>$cookie) if $cookie; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 16 | return $self->psgi_header(@o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # The list is auto generated and modified with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # perl -nle '/^sub (\w+)/ and $sub=$1; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # /^}\s*$/ and do { print $sub if $code{$sub} =~ /([\%\$]ENV|http\()/; undef $sub };\ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # $code{$sub} .= "$_\n" if $sub; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # /^\s*package [^C]/ and exit' \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # `perldoc -l CGI` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 12 | for my $method (qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | url_param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | url | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | cookie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | raw_cookie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | _name_and_path_from_env | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | request_method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | content_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | path_translated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | request_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | Accept | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | user_agent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | virtual_host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | remote_host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | remote_addr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | referer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | server_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | server_software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | virtual_port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | server_port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | server_protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | http | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | https | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | remote_ident | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | auth_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | remote_user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | user_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | read_multipart | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | read_multipart_related | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | env_query_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # skip methods the installed CGI.pm doesn't have (env_query_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # is new in CGI.pm 4.x) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 348 | ▶ | next unless CGI->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 12 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 123 | ▶ | *$method = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 123 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 123 | my $super = "SUPER::$method"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 123 | local *ENV = $self->{psgi_env}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 123 | $self->$super(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 348 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 36 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 36 | CGI::initialize_globals(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||