| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # No foreign shared library may be linked by the loader, any object inside the | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # binary, or any object its first start extracts into the PAR cache (libperl, the | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # inner executable); on Linux the highest GLIBC_x.y must stay within the floor. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # lib-gate.pl <binary> <linux|macos|windows> | ||||||||||||||||||||||||||||||||||||||||||
| 6 | package DzilBinary::LibGate; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 162 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 162 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 162 | ▶ | use Archive::Zip qw( AZ_OK ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 162 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 162 | ▶ | use File::Find (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 162 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 162 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 162 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 162 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 108 | our $GLIBC_FLOOR = '2.28'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 108 | our $START_TIMEOUT = 60; # seconds the start may take before it is killed | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 108 | my @SYSTEM = ( | |||||||||||||||||||||||||||||||||||||||||
| 21 | linux => [ 'libc.so*', 'libm.so*', 'libpthread.so*', 'libdl.so*', 'librt.so*', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 'libutil.so*', 'libgcc_s.so*', 'ld-linux-*', 'linux-vdso*' ], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | macos => [ '/usr/lib/*', '/System/*' ], | ||||||||||||||||||||||||||||||||||||||||||
| 24 | windows => [ 'api-ms-*' ], | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 108 | my %SYSTEM = @SYSTEM; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # the perl shared library the start must have extracted (matched on the basename) | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 108 | my %PERL_LIB = ( linux => 'libperl.so*', macos => 'libperl.dylib', windows => 'perl5*.dll' ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1899 | ▶ | sub glob_re { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glob_re: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1899 | my ($g) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1899 | my $re = join '.*', map { quotemeta } split /\*/, $g, -1; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1899 | return qr/\A$re\z/i; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # A predicate: true for a library name the allowlist or a packed name covers. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 407 | ▶ | sub covered { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
covered: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 407 | my ($allowed, $packed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 407 | my @re = map { glob_re($_) } @$allowed; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 407 | my %packed = map { lc($_) => 1 } @$packed; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 1175 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1175 | my ($lib) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1175 | my ($base) = $lib =~ m{([^/\\]+)\z}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 1175 | ▶ | return $packed{lc $lib} || (defined $base && $packed{lc $base}) || scalar grep { $lib =~ $_ } @re; | ||||||||||||||||||||||||||||||||||||||||
|
Condition87%7/8
$packed{lc $lib} || defined $base && $packed{lc $base} || scalar grep({$lib =~ /$_/;} @re)
$packed{lc $lib} or defined $base and $packed{lc $base}
defined $base and $packed{lc $base}
MC/DC66%2/3
$packed{lc $lib} || defined $base && $packed{lc $base} || scalar grep({$lib =~ /$_/;} @re)
$packed{lc $lib}
defined $base
$packed{lc $base}
Truth table75%3/4
A or B and C
A= $packed{lc $lib}B= defined $baseC= $packed{lc $base}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 407 | }; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # %links: object => [library names]; returns sorted "lib (linked by object)" strings. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 341 | ▶ | sub violations { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violations: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 341 | my ($links, $allowed, $packed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 341 | my $covered = covered($allowed, $packed); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 341 | my @v; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 341 | for my $obj (keys %$links) { | |||||||||||||||||||||||||||||||||||||||||
| 55 | 459 | for my $lib (@{ $links->{$obj} }) { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 921 | ▶ | push @v, "$lib (linked by $obj)" unless $covered->($lib); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 341 | return sort @v; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # The distinct library names violations() flags, sorted. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 64 | ▶ | sub foreign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
foreign: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 64 | my ($links, $allowed, $packed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 64 | my $covered = covered($allowed, $packed); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 64 | my %f = map { $_ => 1 } grep { !$covered->($_) } map { @$_ } values %$links; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 64 | return sort keys %f; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 356 | ▶ | sub glibc_cmp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glibc_cmp: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 356 | my @a = split /\./, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 356 | my @b = split /\./, $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 356 | ▶ | while (@a || @b) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@a or @b
MC/DC50%1/2
@a or @b
@a
@b
Truth table66%2/3
A or B
A= @aB= @b
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 712 | ▶ | my ($x, $y) = (shift(@a) // 0, shift(@b) // 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
shift @a // 0
shift @b // 0
MC/DC0%0/1
shift @a // 0
shift @a
MC/DC0%0/1
shift @b // 0
shift @b
Truth table50%1/2
A
A= shift @a
Truth table50%1/2
A
A= shift @b
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 712 | ▶ | return $x <=> $y if $x != $y; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 58 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 150 | ▶ | sub glibc_max { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glibc_max: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 150 | my $max; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 150 | ▶ | for my $v (@_) { $max = $v if !defined $max || glibc_cmp($v, $max) > 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $max or glibc_cmp($v, $max) > 0
MC/DC100%2/2
not defined $max or glibc_cmp($v, $max) > 0
not defined $max
glibc_cmp($v, $max) > 0
Truth table100%3/3
not(A) or B
A= not defined $maxB= glibc_cmp($v, $max) > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 150 | return $max; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # --- CLI side (needs ldd / otool / objdump and real objects) --------------- | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 153 | ▶ | sub unpack_archive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack_archive: called CC=7 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 153 | my ($archive, $dest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 153 | my $zip = Archive::Zip->new; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 153 | ▶ | die "cannot read $archive as an archive\n" unless $zip->read($archive) == AZ_OK; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 153 | for my $m ($zip->members) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | 205 | ▶ | next if $m->isDirectory; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 205 | my $n = $m->fileName; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 205 | ▶ | next if $n =~ m{(?:\A|/)\.\.(?:/|\z)} || $n =~ m{\A/}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$n =~ m[(?:\A|/)\.\.(?:/|\z)] or $n =~ m[\A/]
MC/DC0%0/2
$n =~ m[(?:\A|/)\.\.(?:/|\z)] or $n =~ m[\A/]
$n =~ m[(?:\A|/)\.\.(?:/|\z)]
$n =~ m[\A/]
Truth table33%1/3
A or B
A= $n =~ m[(?:\A|/)\.\.(?:/|\z)]B= $n =~ m[\A/]
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 205 | my $to = File::Spec->catfile($dest, split m{/}, $n); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 205 | File::Path::make_path(File::Basename::dirname($to)); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 205 | ▶ | $m->extractToFileNamed($to) == AZ_OK or die "cannot extract $n\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 286 | ▶ | sub is_native { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_native: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 286 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 286 | ▶ | open my $fh, '<:raw', $file or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 286 | read($fh, my $magic, 4); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 286 | ▶ | return 0 unless defined $magic && length $magic >= 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $magic and length $magic >= 2
MC/DC0%0/2
defined $magic and length $magic >= 2
defined $magic
length $magic >= 2
Truth table33%1/3
A and B
A= defined $magicB= length $magic >= 2
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 286 | ▶ | return $magic =~ /\A(?:\x7fELF|MZ|\xfe\xed\xfa[\xce\xcf]|[\xce\xcf]\xfa\xed\xfe|\xca\xfe\xba\xbe)/s ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # Runs a tool; dies when it cannot be spawned (naming it). Returns (output, exit code). | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 505 | ▶ | sub run_tool { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tool: called CC=13 SCAR=27.4
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 505 | my ($merge_stderr, @cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 505 | ▶ | return run_tool_win32($merge_stderr, @cmd) if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 458 | ▶ | pipe(my $r, my $w) or die "pipe: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 458 | ▶ | pipe(my $er, my $ew) or die "pipe: $!\n"; # exec-failure channel, closed on exec | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 458 | ▶ | my $pid = fork // die "fork: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("fork: $!\n")
MC/DC0%0/1
fork // die("fork: $!\n")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 458 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 105 | close $r; close $er; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 105 | ▶ | open STDOUT, '>&', $w or POSIX::_exit(127); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 105 | ▶ | open STDERR, '>&', $w or POSIX::_exit(127) if $merge_stderr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$merge_stderr && (open(STDERR, '>&', $w) || POSIX::_exit(127))
open STDERR, ">&", $w or POSIX::_exit(127)
MC/DC0%0/3
$merge_stderr && (open(STDERR, '>&', $w) || POSIX::_exit(127))
$merge_stderr
open STDERR, ">&", $w
POSIX::_exit(127)
Truth table0%0/4
A && B or C
A= $merge_stderrB= open STDERR, ">&", $wC= POSIX::_exit(127)
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 105 | { exec @cmd } | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | { my $o = select $ew; $| = 1; select $o } | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | print $ew "$!"; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | POSIX::_exit(127); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 353 | close $w; close $ew; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 353 | my $out = do { local $/; <$r> }; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 353 | my $failed = do { local $/; <$er> }; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 353 | close $r; close $er; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 353 | waitpid $pid, 0; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 353 | ▶ | die "cannot run $cmd[0]: $failed\n" if defined $failed && length $failed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $failed and length $failed
MC/DC50%1/2
defined $failed and length $failed
defined $failed
length $failed
Truth table66%2/3
A and B
A= defined $failedB= length $failed
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 347 | ▶ | die "$cmd[0] was killed by signal " . ($? & 127) . "\n" if $? & 127; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 341 | ▶ | return ($out // '', $? >> 8); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # Win32: fork is emulated there and pipe handles are not duplicated reliably | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # into the pseudo-process (perlfork, BUGS), so the pipe + fork + exec above never | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # sees EOF. A list-form pipe open spawns the tool directly. STDOUT only: the | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # tool's STDERR stays the gate's, and merge_stderr (only ldd, Linux) dies. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # Win32 keeps only the low byte of an exit code and has no signals: a killed or | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # crashed tool shows as that byte, the signal check never fires there. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 41 | ▶ | sub run_tool_win32 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tool_win32: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 41 | my ($merge_stderr, @cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 41 | ▶ | die "cannot run $cmd[0]: merging its STDERR is not supported on MSWin32\n" if $merge_stderr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 28 | ▶ | open my $fh, '-|', @cmd or die "cannot run $cmd[0]: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 24 | my $out = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 24 | close $fh; # false on a non-zero exit; $? holds the status either way | |||||||||||||||||||||||||||||||||||||||||
| 148 | 24 | ▶ | die "cannot wait for $cmd[0]: $!\n" if $? == -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 24 | ▶ | die "$cmd[0] was killed by signal " . ($? & 127) . "\n" if $? & 127; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 20 | ▶ | return ($out // '', $? >> 8); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # Unix: the child leads its own process group, so a timeout takes the loader's | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # children with it. Dies when the binary cannot be executed (naming it). | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 92 | ▶ | sub spawn_unix { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn_unix: called CC=10 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 92 | my ($binary, $null) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 92 | ▶ | pipe(my $er, my $ew) or die "pipe: $!\n"; # exec-failure channel, closed on exec | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 92 | ▶ | my $pid = fork // die "fork: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("fork: $!\n")
MC/DC0%0/1
fork // die("fork: $!\n")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 92 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 23 | close $er; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $fail = sub { syswrite $ew, $_[0]; POSIX::_exit(127) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 23 | ▶ | setpgrp(0, 0) or $fail->("setpgrp: $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 23 | ▶ | open(STDIN, '<', $null) && open(STDOUT, '>', $null) && open(STDERR, '>', $null) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
open STDIN, "<", $null and open STDOUT, ">", $null and open STDERR, ">", $null
open STDIN, "<", $null and open STDOUT, ">", $null
MC/DC0%0/3
open STDIN, "<", $null and open STDOUT, ">", $null and open STDERR, ">", $null
open STDIN, "<", $null
open STDOUT, ">", $null
open STDERR, ">", $null
Truth table25%1/4
A and B and C
A= open STDIN, "<", $nullB= open STDOUT, ">", $nullC= open STDERR, ">", $null
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | or $fail->("cannot open $null: $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 23 | { exec { $binary } $binary, '--help' } | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $fail->("$!"); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 69 | close $ew; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 69 | my $failed = do { local $/; <$er> }; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 69 | close $er; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 69 | ▶ | if (defined $failed && length $failed) { waitpid $pid, 0; die "cannot start $binary: $failed\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $failed and length $failed
MC/DC50%1/2
defined $failed and length $failed
defined $failed
length $failed
Truth table66%2/3
A and B
A= defined $failedB= length $failed
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 68 | return $pid; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # Win32 (fork is emulated there): spawn with system 1, STDOUT/STDERR pointed at | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # the null device for the call and restored after it. The gate never reads | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # stdin, so it stays on the null device. | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub spawn_win32 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn_win32: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my ($binary, $null) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | open STDIN, '<', $null or die "cannot open $null: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | open my $out, '>&', \*STDOUT or die "cannot dup STDOUT: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | open my $err, '>&', \*STDERR or die "cannot dup STDERR: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my ($pid, $why); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if (open(STDOUT, '>', $null) && open(STDERR, '>', $null)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
open STDOUT, ">", $null and open STDERR, ">", $null
MC/DC0%0/2
open STDOUT, ">", $null and open STDERR, ">", $null
open STDOUT, ">", $null
open STDERR, ">", $null
Truth table0%0/3
A and B
A= open STDOUT, ">", $nullB= open STDERR, ">", $null
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $pid = system 1, File::Spec->canonpath($binary), '--help'; # C:/x -> C:\x for CreateProcess | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $why = "$!"; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | else { $why = "cannot open $null: $!" } | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | open STDOUT, '>&', $out or die "cannot restore STDOUT: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | open STDERR, '>&', $err or die "cannot restore STDERR: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | die "cannot start $binary: $why\n" unless defined $pid && $pid > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pid and $pid > 0
MC/DC0%0/2
defined $pid and $pid > 0
defined $pid
$pid > 0
Truth table0%0/3
A and B
A= defined $pidB= $pid > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return $pid; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # Starts the binary once as the install scripts' warm-up does: <binary> --help, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # stdin at EOF, output discarded, exit status ignored, the PAR cache in $cache | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # (PAR_GLOBAL_TEMP is the exact cache directory). A start still running after | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # $START_TIMEOUT seconds is killed with its process group (Unix) or process tree | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # (Win32); a timeout alone is not a failure. Dies when it cannot be started. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 92 | ▶ | sub start_binary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_binary: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 92 | my ($binary, $cache) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 92 | local $ENV{PAR_GLOBAL_TEMP} = $cache; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 92 | my $null = File::Spec->devnull; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 92 | ▶ | my $pid = $^O eq 'MSWin32' ? spawn_win32($binary, $null) : spawn_unix($binary, $null); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 68 | my $deadline = Time::HiRes::time() + $START_TIMEOUT; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 68 | ▶ | while (waitpid($pid, POSIX::WNOHANG()) == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 308 | ▶ | if (Time::HiRes::time() >= $deadline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 12 | kill -9, $pid; # negative signal: Unix the process group $pid leads, Win32 the process tree | |||||||||||||||||||||||||||||||||||||||||
| 209 | 12 | waitpid $pid, 0; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 12 | ▶ | print STDERR "$binary --help timed out after ${START_TIMEOUT}s: killed it with its ", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | ($^O eq 'MSWin32' ? 'process tree' : 'process group'), "; checking what the cache holds\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 296 | Time::HiRes::sleep(0.1); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 56 | return; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | # native files anywhere under $dir, whatever their name: [ path, label ], sorted | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 68 | ▶ | sub cache_objects { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_objects: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 68 | my ($dir) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 68 | my @found; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 403 | ▶ | File::Find::find({ no_chdir => 1, wanted => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 403 | ▶ | push @found, $File::Find::name if -f $_ && is_native($_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $_ and is_native($_)
MC/DC50%1/2
-f $_ and is_native($_)
-f $_
is_native($_)
Truth table66%2/3
A and B
A= -f $_B= is_native($_)
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 68 | } }, $dir); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 68 | return map { [ $_, join '/', 'cache', File::Spec->splitdir(File::Spec->abs2rel($_, $dir)) ] } sort @found; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 263 | ▶ | sub capture { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 263 | my (@cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 263 | my ($out, $rc) = run_tool(0, @cmd); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 192 | ▶ | die "$cmd[0] failed (exit $rc) on $cmd[-1]\n" if $rc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 191 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | # ldd: only "not a dynamic executable" / "statically linked" may fail. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 169 | ▶ | sub capture_ldd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture_ldd: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 169 | my ($obj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 169 | my ($out, $rc) = run_tool(1, 'ldd', $obj); | |||||||||||||||||||||||||||||||||||||||||
| 240 | 133 | ▶ | return $out if !$rc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return '' if $out =~ /not a dynamic|statically linked/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | die "ldd failed (exit $rc) on $obj\n"; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 299 | ▶ | sub linked { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
linked: called CC=11 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 299 | my ($platform, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 299 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 299 | ▶ | if ($platform eq 'linux') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 169 | for (split /\n/, capture_ldd($obj)) { | |||||||||||||||||||||||||||||||||||||||||
| 250 | 168 | ▶ | if (/^\s*(\S+)\s+=>/) { $seen{ File::Basename::basename($1) } = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | elsif (m{^\s*(/\S+|\S+)\s+\(0x}) { $seen{ File::Basename::basename($1) } = 1 } | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | elsif ($platform eq 'macos') { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 19 | my @l = split /\n/, capture('otool', '-L', $obj); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 12 | shift @l; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 12 | for (@l) { | |||||||||||||||||||||||||||||||||||||||||
| 258 | 18 | ▶ | next unless /^\s+(\S+)\s+\(/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 18 | my $n = $1; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 18 | ▶ | $n = File::Basename::basename($n) if $n =~ /\A\@/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 18 | $seen{$n} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 111 | ▶ | for (split /\n/, capture('objdump', '-p', $obj)) { $seen{ lc $1 } = 1 if /DLL Name:\s*(\S+)/ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 225 | return [ sort keys %seen ]; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 133 | ▶ | sub glibc_versions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glibc_versions: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 133 | my ($obj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 133 | my %v; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 133 | my $out = capture('objdump', '-T', $obj); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 99 | ▶ | $v{$1} = 1 while $out =~ /GLIBC_(\d+(?:\.\d+)*)/g; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 99 | return keys %v; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | # What the gate judges, without the verdict: the links of the loader, of every | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # object inside $archive and of every native file its first start extracts into | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # the PAR cache, and the names of all of those (packed). $report gets the cache | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # listing before the perl library check. Returns | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # { links => { label => [names] }, packed => [names], glibc => { version => 1 }, checked => count }. | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 153 | ▶ | sub inspect_binary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inspect_binary: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 153 | my ($archive, $platform, $report) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 153 | ▶ | die "unknown platform '$platform' (linux, macos, windows)\n" unless $SYSTEM{$platform}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 153 | my $tmp = File::Temp->newdir; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 153 | unpack_archive($archive, "$tmp"); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 153 | my @objects; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 812 | ▶ | File::Find::find({ no_chdir => 1, wanted => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 812 | ▶ | push @objects, $File::Find::name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-f $_ and /\.(?:so(?:\.[\d.]+)?|dylib|bundle|dll|pyd)\z/i
MC/DC100%2/2
-f $_ and /\.(?:so(?:\.[\d.]+)?|dylib|bundle|dll|pyd)\z/i
-f $_
/\.(?:so(?:\.[\d.]+)?|dylib|bundle|dll|pyd)\z/i
Truth table100%3/3
A and B
A= -f $_B= /\.(?:so(?:\.[\d.]+)?|dylib|bundle|dll|pyd)\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | if -f $_ && /\.(?:so(?:\.[\d.]+)?|dylib|bundle|dll|pyd)\z/i; | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 153 | } }, "$tmp"); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 153 | ▶ | my $packed_name = sub { $platform eq 'windows' ? lc File::Basename::basename($_[0]) : File::Basename::basename($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 153 | my @packed = map { $packed_name->($_) } @objects; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 153 | ▶ | unshift @objects, $archive if is_native($archive); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 153 | ▶ | die "no shared objects to check in $archive: the gate proved nothing\n" unless @objects; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 151 | my (%links, %glibc); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 290 | ▶ | my $inspect = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 290 | my ($o, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 290 | $links{$label} = linked($platform, $o); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 219 | ▶ | $glibc{$_} = 1 for $platform eq 'linux' ? glibc_versions($o) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 151 | }; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 151 | ▶ | $inspect->($_, $_ eq $archive ? "$archive (loader)" : File::Spec->abs2rel($_, "$tmp")) for @objects; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # libperl, the inner executable and PAR's own XS live in the loader, not in the | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # zip: only a start shows them | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 92 | my $cache = File::Temp->newdir; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 92 | start_binary($archive, "$cache"); | |||||||||||||||||||||||||||||||||||||||||
| 311 | 68 | my @cached = cache_objects("$cache"); | |||||||||||||||||||||||||||||||||||||||||
| 312 | 68 | $report->("PAR cache after the start: " . scalar(@cached) . " object(s)\n", map({ " $_->[1]\n" } @cached)); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 68 | my $perl_re = glob_re($PERL_LIB{$platform}); | |||||||||||||||||||||||||||||||||||||||||
| 314 | die "the start extracted no perl library into PAR_GLOBAL_TEMP: the gate proved nothing about libperl\n" | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 68 | ▶ | unless grep { File::Basename::basename($_->[0]) =~ $perl_re } @cached; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 65 | for my $c (@cached) { | |||||||||||||||||||||||||||||||||||||||||
| 317 | 101 | $inspect->(@$c); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 55 | push @packed, $packed_name->($c->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 19 | return { links => \%links, packed => \@packed, glibc => \%glibc, checked => @objects + @cached }; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | # The system libraries $platform's objects may link; on Windows also every name | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # in %$links that System32 holds. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 58 | ▶ | sub allowlist { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allowlist: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 58 | my ($platform, $links) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 58 | my @allowed = @{ $SYSTEM{$platform} }; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 58 | ▶ | if ($platform eq 'windows') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 46 | ▶ | my $sys = File::Spec->catdir($ENV{SystemRoot} // 'C:\\Windows', 'System32'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"SystemRoot"} // "C:\\Windows"
MC/DC0%0/1
$ENV{"SystemRoot"} // "C:\\Windows"
$ENV{"SystemRoot"}
Truth table50%1/2
A
A= $ENV{"SystemRoot"}
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 46 | my %names = map { $_ => 1 } map { @$_ } values %$links; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 46 | push @allowed, map { quotemeta } grep { -e File::Spec->catfile($sys, $_) } sort keys %names; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 46 | @allowed = map { s/\\//gr } @allowed; # names have no '*', plain strings | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 58 | return @allowed; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 129 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 129 | my ($archive, $platform) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 129 | local $| = 1; # nothing buffered on STDOUT when run_tool / the start fork | |||||||||||||||||||||||||||||||||||||||||
| 340 | 129 | ▶ | my $seen = inspect_binary($archive, $platform, sub { print @_ }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 12 | my %links = %{ $seen->{links} }; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 12 | my %glibc = %{ $seen->{glibc} }; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 12 | my @v = violations(\%links, [allowlist($platform, \%links)], $seen->{packed}); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 12 | my $fail = 0; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 12 | ▶ | if (@v) { print STDERR "foreign shared libraries:\n", map({ " $_\n" } @v); $fail = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 12 | ▶ | if ($platform eq 'linux' && !%glibc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$platform eq "linux" and not %glibc
MC/DC100%2/2
$platform eq "linux" and not %glibc
$platform eq "linux"
not %glibc
Truth table100%3/3
A and not(B)
A= $platform eq "linux"B= not %glibc
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | print STDERR "glibc check did not run: no GLIBC_ version found in any object\n"; $fail = 1; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | elsif ($platform eq 'linux') { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | my $max = glibc_max(keys %glibc); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | ▶ | if (glibc_cmp($max, $GLIBC_FLOOR) > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | print STDERR "glibc $max needed, floor is $GLIBC_FLOOR\n"; $fail = 1; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | else { print "highest glibc symbol version: $max (floor $GLIBC_FLOOR)\n" } | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 12 | ▶ | print "lib-gate $platform: $seen->{checked} object(s) checked, " . ($fail ? 'FAILED' : 'ok') . "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 12 | return $fail; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 129 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 129 | my ($archive, $platform) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 129 | ▶ | die "usage: lib-gate.pl <binary> <linux|macos|windows>\n" unless defined $platform; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 129 | my $rc = eval { run($archive, $platform) }; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 24 | ▶ | if ($@) { print STDERR $@; return 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 12 | return $rc; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 108 | require File::Path; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 108 | ▶ | exit main(@ARGV) unless caller; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 1; | ||||||||||||||||||||||||||||||||||||||||||