| 1 | package Net::SFTP::Foreign::Helpers; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 3 | our $VERSION = '1.74_06'; | |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp qw(croak carp); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | 3 | our @CARP_NOT = qw(Net::SFTP::Foreign); | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Scalar::Util qw(tainted); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 3 | require Exporter; | |||||||||||||||||||||||||||||
| 14 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||
| 15 | 3 | our @EXPORT = qw( _sort_entries | |||||||||||||||||||||||||||||
| 16 | _gen_wanted | ||||||||||||||||||||||||||||||
| 17 | _ensure_list | ||||||||||||||||||||||||||||||
| 18 | _catch_tainted_args | ||||||||||||||||||||||||||||||
| 19 | _debug | ||||||||||||||||||||||||||||||
| 20 | _gen_converter | ||||||||||||||||||||||||||||||
| 21 | _hexdump | ||||||||||||||||||||||||||||||
| 22 | $debug | ||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||
| 24 | 3 | our @EXPORT_OK = qw( _is_lnk | |||||||||||||||||||||||||||||
| 25 | _is_dir | ||||||||||||||||||||||||||||||
| 26 | _is_reg | ||||||||||||||||||||||||||||||
| 27 | _do_nothing | ||||||||||||||||||||||||||||||
| 28 | _glob_to_regex | ||||||||||||||||||||||||||||||
| 29 | _file_part | ||||||||||||||||||||||||||||||
| 30 | _umask_save_and_set | ||||||||||||||||||||||||||||||
| 31 | _tcroak | ||||||||||||||||||||||||||||||
| 32 | _untaint ); | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 3 | our $debug; | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | eval "use Time::HiRes 'time'" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Net::SFTP::Foreign::Helpers::debug and $Net::SFTP::Foreign::Helpers::debug & 256
MC/DC0%0/2
$Net::SFTP::Foreign::Helpers::debug and $Net::SFTP::Foreign::Helpers::debug & 256
$Net::SFTP::Foreign::Helpers::debug
$Net::SFTP::Foreign::Helpers::debug & 256
Truth table33%1/3
A and B
A= $Net::SFTP::Foreign::Helpers::debugB= $Net::SFTP::Foreign::Helpers::debug & 256
| |||||||||||||||||||||||||||||||
| 38 | if ($debug and $debug & 256) | ||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _debug { | ||||||||||||||||||||||||||||
|
Subroutine
_debug: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 42 | 0 | local ($\, $!); | |||||||||||||||||||||||||||||
| 43 | 0 | my $caller = ''; | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $debug & 8192) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 45 | 0 | $caller = (caller 1)[3]; | |||||||||||||||||||||||||||||
| 46 | 0 | $caller =~ s/[\w:]*:://; | |||||||||||||||||||||||||||||
| 47 | 0 | $caller .= ': '; | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $line = join(' ', map { defined $_ ? $_ : '<undef>' } @_); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($debug & 256) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 53 | 0 | my $ts = sprintf("%010.5f", time); | |||||||||||||||||||||||||||||
| 54 | 0 | print STDERR "#$$ $ts $caller $line\n"; | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||
| 57 | 0 | print STDERR "# $caller $line\n"; | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub _hexdump { | ||||||||||||||||||||||||||||
|
Subroutine
_hexdump: not called CC=3 SCAR=21.1
| |||||||||||||||||||||||||||||||
| 62 | 0 | local ($\, $!); | |||||||||||||||||||||||||||||
| 63 | 3 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 64 | 0 | my $data = shift; | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | while ($data =~ /(.{1,32})/smg) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 0 | my $line=$1; | |||||||||||||||||||||||||||||
| 67 | 0 | my @c= (( map { sprintf "%02x",$_ } unpack('C*', $line)), | |||||||||||||||||||||||||||||
| 68 | ((" ") x 32))[0..31]; | ||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $line=~s/(.)/ my $c=$1; unpack("c",$c)>=32 ? $c : '.' /egms; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 70 | 0 | local $\; | |||||||||||||||||||||||||||||
| 71 | 0 | print STDERR join(" ", @c, '|', $line), "\n"; | |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub _do_nothing {} | ||||||||||||||||||||||||||||
|
Subroutine
_do_nothing: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||
| 78 | 3 | my $has_sk; | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub _has_sk { | ||||||||||||||||||||||||||||
|
Subroutine
_has_sk: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | unless (defined $has_sk) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 81 | 0 | local $@; | |||||||||||||||||||||||||||||
| 82 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||
| 83 | 0 | eval { require Sort::Key }; | |||||||||||||||||||||||||||||
| 84 | 0 | $has_sk = ($@ eq ''); | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | 0 | return $has_sk; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub _sort_entries { | ||||||||||||||||||||||||||||
|
Subroutine
_sort_entries: not called CC=2 SCAR=15.7
| |||||||||||||||||||||||||||||||
| 91 | 0 | my $e = shift; | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (_has_sk) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | &Sort::Key::keysort_inplace(sub { $_->{filename} }, $e); | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||||
| 96 | 0 | @$e = sort { $a->{filename} cmp $b->{filename} } @$e; | |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub _gen_wanted { | ||||||||||||||||||||||||||||
|
Subroutine
_gen_wanted: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||
| 101 | 0 | my ($ow, $onw) = my ($w, $nw) = @_; | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (ref $w eq 'Regexp') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $w = sub { $_[1]->{filename} =~ $ow } | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 104 | 0 | } | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (ref $nw eq 'Regexp') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $nw = sub { $_[1]->{filename} !~ $onw } | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 108 | 0 | } | |||||||||||||||||||||||||||||
| 109 | elsif (defined $nw) { | ||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $nw = sub { !&$onw }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (defined $w and defined $nw) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $w and defined $nw
MC/DC0%0/2
defined $w and defined $nw
defined $w
defined $nw
Truth table0%0/3
A and B
A= defined $wB= defined $nw
| |||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return sub { &$nw and &$w } | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 115 | 0 | } | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return $w || $nw; | ||||||||||||||||||||||||||||
|
Condition0%0/3
$w || $nw
MC/DC0%0/2
$w || $nw
$w
$nw
Truth table0%0/3
A || B
A= $wB= $nw
| |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub _ensure_list { | ||||||||||||||||||||||||||||
|
Subroutine
_ensure_list: not called CC=3 SCAR=20.3
| |||||||||||||||||||||||||||||||
| 121 | 0 | my $l = shift; | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return () unless defined $l; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 123 | 0 | local $@; | |||||||||||||||||||||||||||||
| 124 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||
| 125 | 0 | local $SIG{__WARN__}; | |||||||||||||||||||||||||||||
| 126 | 3 | ▶ | no warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | (eval { @$l; 1 } ? @$l : $l); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub _glob_to_regex { | ||||||||||||||||||||||||||||
|
Subroutine
_glob_to_regex: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||
| 131 | 0 | my ($glob, $strict_leading_dot, $ignore_case) = @_; | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | 0 | my ($regex, $in_curlies, $escaping); | |||||||||||||||||||||||||||||
| 134 | 0 | my $wildcards = 0; | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | 0 | my $first_byte = 1; | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | while ($glob =~ /\G(.)/g) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 138 | 0 | my $char = $1; | |||||||||||||||||||||||||||||
| 139 | # print "char: $char\n"; | ||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 141 | 0 | $escaping = 1; | |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($first_byte) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($strict_leading_dot) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $regex .= '(?=[^\.])' unless $char eq '.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||
| 148 | 0 | $first_byte = 0; | |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($char eq '/') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 151 | 0 | $first_byte = 1; | |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ($escaping) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 154 | 0 | $regex .= quotemeta $char; | |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||||
| 157 | 0 | $wildcards++; | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($char eq '*') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 159 | 0 | $regex .= ".*"; | |||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||
| 161 | elsif ($char eq '?') { | ||||||||||||||||||||||||||||||
| 162 | 0 | $regex .= '.' | |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||
| 164 | elsif ($char eq '{') { | ||||||||||||||||||||||||||||||
| 165 | 0 | $regex .= '(?:(?:'; | |||||||||||||||||||||||||||||
| 166 | 0 | ++$in_curlies; | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||
| 168 | elsif ($char eq '}') { | ||||||||||||||||||||||||||||||
| 169 | 0 | $regex .= "))"; | |||||||||||||||||||||||||||||
| 170 | 0 | --$in_curlies; | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $in_curlies < 0 | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 172 | and croak "invalid glob pattern"; | ||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||
| 174 | ▶ | elsif ($char eq ',' && $in_curlies) { | |||||||||||||||||||||||||||||
|
Condition0%0/3
$char eq "," and $in_curlies
MC/DC0%0/2
$char eq "," and $in_curlies
$char eq ","
$in_curlies
Truth table0%0/3
A and B
A= $char eq ","B= $in_curlies
| |||||||||||||||||||||||||||||||
| 175 | 0 | $regex .= ")|(?:"; | |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||
| 177 | elsif ($char eq '[') { | ||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($glob =~ /\G((?:\\.|[^\]])+)\]/g) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 179 | 0 | $regex .= "[$1]" | |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||
| 182 | 0 | croak "invalid glob pattern"; | |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||
| 185 | else { | ||||||||||||||||||||||||||||||
| 186 | 0 | $wildcards--; | |||||||||||||||||||||||||||||
| 187 | 0 | $regex .= quotemeta $char; | |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | 0 | $escaping = 0; | |||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | croak "invalid glob pattern" if $in_curlies; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $re = $ignore_case ? qr/^$regex$/i : qr/^$regex$/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | wantarray ? ($re, ($wildcards > 0 ? 1 : undef)) : $re | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub _tcroak { | ||||||||||||||||||||||||||||
|
Subroutine
_tcroak: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if (${^TAINT} > 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 203 | 0 | push @_, " while running with -T switch"; | |||||||||||||||||||||||||||||
| 204 | 0 | goto &croak; | |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if (${^TAINT} < 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 207 | 0 | push @_, " while running with -t switch"; | |||||||||||||||||||||||||||||
| 208 | 0 | goto &carp; | |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub _catch_tainted_args { | ||||||||||||||||||||||||||||
|
Subroutine
_catch_tainted_args: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||
| 213 | 0 | my $i; | |||||||||||||||||||||||||||||
| 214 | 0 | for (@_) { | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | next unless $i++; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if (tainted($_)) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 217 | 0 | my (undef, undef, undef, $subn) = caller 1; | |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $msg = ( $subn =~ /::([a-z]\w*)$/ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 219 | ? "Insecure argument '$_' on '$1' method call" | ||||||||||||||||||||||||||||||
| 220 | : "Insecure argument '$_' on method call" ); | ||||||||||||||||||||||||||||||
| 221 | 0 | _tcroak($msg); | |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||
| 223 | elsif (ref($_)) { | ||||||||||||||||||||||||||||||
| 224 | 0 | for (grep tainted($_), | |||||||||||||||||||||||||||||
| 225 | 0 | do { local ($@, $SIG{__DIE__}); eval { values %$_ }}) { | |||||||||||||||||||||||||||||
| 226 | 0 | my (undef, undef, undef, $subn) = caller 1; | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my $msg = ( $subn =~ /::([a-z]\w*)$/ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 228 | ? "Insecure argument on '$1' method call" | ||||||||||||||||||||||||||||||
| 229 | : "Insecure argument on method call" ); | ||||||||||||||||||||||||||||||
| 230 | 0 | _tcroak($msg); | |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | sub _gen_dos2unix { | ||||||||||||||||||||||||||||
|
Subroutine
_gen_dos2unix: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 237 | 0 | my $unix2dos = shift; | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my $name = ($unix2dos ? 'unix2dos' : 'dos2unix'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 239 | 0 | my $previous; | |||||||||||||||||||||||||||||
| 240 | my $done; | ||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | $done and die "Internal error: bad calling sequence for $name transformation"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 243 | 0 | my $adjustment = 0; | |||||||||||||||||||||||||||||
| 244 | 0 | for (@_) { | |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if ($debug and $debug & 128) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Net::SFTP::Foreign::Helpers::debug and $Net::SFTP::Foreign::Helpers::debug & 128
MC/DC0%0/2
$Net::SFTP::Foreign::Helpers::debug and $Net::SFTP::Foreign::Helpers::debug & 128
$Net::SFTP::Foreign::Helpers::debug
$Net::SFTP::Foreign::Helpers::debug & 128
Truth table0%0/3
A and B
A= $Net::SFTP::Foreign::Helpers::debugB= $Net::SFTP::Foreign::Helpers::debug & 128
| |||||||||||||||||||||||||||||||
| 246 | 0 | _debug ("before $name: previous: $previous, data follows..."); | |||||||||||||||||||||||||||||
| 247 | 0 | _hexdump($_); | |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (length) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ($previous) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 251 | 0 | $adjustment++; | |||||||||||||||||||||||||||||
| 252 | 0 | $_ = "\x0d$_"; | |||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||
| 254 | 0 | $adjustment -= $previous = s/\x0d\z//s; | |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($unix2dos) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 256 | 0 | $adjustment += s/(?<!\x0d)\x0a/\x0d\x0a/gs; | |||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||
| 259 | 0 | $adjustment -= s/\x0d\x0a/\x0a/gs; | |||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||
| 262 | elsif ($previous) { | ||||||||||||||||||||||||||||||
| 263 | 0 | $previous = 0; | |||||||||||||||||||||||||||||
| 264 | 0 | $done = 1; | |||||||||||||||||||||||||||||
| 265 | 0 | $adjustment++; | |||||||||||||||||||||||||||||
| 266 | 0 | $_ = "\x0d"; | |||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ($debug and $debug & 128) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Net::SFTP::Foreign::Helpers::debug and $Net::SFTP::Foreign::Helpers::debug & 128
MC/DC0%0/2
$Net::SFTP::Foreign::Helpers::debug and $Net::SFTP::Foreign::Helpers::debug & 128
$Net::SFTP::Foreign::Helpers::debug
$Net::SFTP::Foreign::Helpers::debug & 128
Truth table0%0/3
A and B
A= $Net::SFTP::Foreign::Helpers::debugB= $Net::SFTP::Foreign::Helpers::debug & 128
| |||||||||||||||||||||||||||||||
| 269 | 0 | _debug ("after $name: previous: $previous, adjustment: $adjustment, data follows..."); | |||||||||||||||||||||||||||||
| 270 | 0 | _hexdump($_); | |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||
| 272 | 0 | return $adjustment; | |||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||
| 275 | 0 | } | |||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub _gen_converter { | ||||||||||||||||||||||||||||
|
Subroutine
_gen_converter: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||
| 278 | 0 | my $conversion = shift; | |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | return undef unless defined $conversion; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if (ref $conversion) { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (ref $conversion eq 'CODE') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 285 | 0 | my $before = length $_[0]; | |||||||||||||||||||||||||||||
| 286 | 0 | $conversion->($_[0]); | |||||||||||||||||||||||||||||
| 287 | 0 | length($_[0]) - $before; | |||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||
| 289 | 0 | } | |||||||||||||||||||||||||||||
| 290 | else { | ||||||||||||||||||||||||||||||
| 291 | 0 | croak "unsupported conversion argument" | |||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||
| 294 | elsif ($conversion eq 'dos2unix') { | ||||||||||||||||||||||||||||||
| 295 | 0 | return _gen_dos2unix(0); | |||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||
| 297 | elsif ($conversion eq 'unix2dos') { | ||||||||||||||||||||||||||||||
| 298 | 0 | return _gen_dos2unix(1); | |||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||
| 300 | else { | ||||||||||||||||||||||||||||||
| 301 | 0 | croak "unknown conversion '$conversion'"; | |||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | use constant S_IFMT => 0170000; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 306 | 3 | ▶ | use constant S_IFLNK => 0120000; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 307 | 3 | ▶ | use constant S_IFDIR => 0040000; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 308 | 3 | ▶ | use constant S_IFREG => 0100000; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub _is_lnk { (S_IFMT & shift) == S_IFLNK } | ||||||||||||||||||||||||||||
|
Subroutine
_is_lnk: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub _is_dir { (S_IFMT & shift) == S_IFDIR } | ||||||||||||||||||||||||||||
|
Subroutine
_is_dir: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | sub _is_reg { (S_IFMT & shift) == S_IFREG } | ||||||||||||||||||||||||||||
|
Subroutine
_is_reg: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | sub _file_part { | ||||||||||||||||||||||||||||
|
Subroutine
_file_part: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 315 | 0 | my $path = shift; | |||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $path =~ m{([^/]*)$} or croak "unable to get file part from path '$path'"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 317 | 0 | $1; | |||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub _untaint { | ||||||||||||||||||||||||||||
|
Subroutine
_untaint: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if (${^TAINT}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 322 | 0 | for (@_) { | |||||||||||||||||||||||||||||
| 323 | 0 | ▶ | defined or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 324 | 0 | ($_) = /(.*)/s | |||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub _umask_save_and_set { | ||||||||||||||||||||||||||||
|
Subroutine
_umask_save_and_set: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 330 | 0 | my $umask = shift; | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if (defined $umask) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 332 | 0 | my $old = umask $umask; | |||||||||||||||||||||||||||||
| 333 | 0 | return bless \$old, 'Net::SFTP::Foreign::Helpers::umask_saver'; | |||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||
| 335 | () | ||||||||||||||||||||||||||||||
| 336 | 0 | } | |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub Net::SFTP::Foreign::Helpers::umask_saver::DESTROY { umask ${$_[0]} } | ||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||
| 340 | 3 | 1; | |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||