prt-auf: guard against using invalid keys in a hash

This commit is contained in:
John McQuah 2023-08-24 19:20:40 -04:00
parent ab4a9ee6fd
commit ae41c77bd4

View File

@ -136,8 +136,8 @@ if (($action =~ /^(listinst|listorphans|dependent)/)
next if (! $dep); next if (! $dep);
if ($action ne "quickdep") { if ($action ne "quickdep") {
$ind = (grep { $_ eq $dep } keys %V_INST) ? "[i]" : "[ ]"; $ind = (grep { $_ eq $dep } keys %V_INST) ? "[i]" : "[ ]";
$dep .= " $V_REPO{$dep}" if ($osearch{verbose}==1); $dep .= " $V_REPO{$dep}" if (($osearch{verbose}==1) and ($V_REPO{$dep}));
$dep .= " $V_REPO{$dep}\n$DESC{$dep}" if ($osearch{verbose}>1); $dep .= " $V_REPO{$dep}\n$DESC{$dep}" if (($osearch{verbose}>1) and ($V_REPO{$dep}) and ($DESC{$dep}));
} }
printf $strf, $ind, $dep unless ($action eq "quickdep"); printf $strf, $ind, $dep unless ($action eq "quickdep");
printf "%s ", $dep if ($action eq "quickdep"); printf "%s ", $dep if ($action eq "quickdep");
@ -534,7 +534,7 @@ sub port_unlock {
open (LL, '>', $prtlocker."-tmp"); open (LL, '>', $prtlocker."-tmp");
foreach my $nl (@newlocks) { print LL "$nl\n" unless $nl =~ /^\s*$/; } foreach my $nl (@newlocks) { print LL "$nl\n" unless $nl =~ /^\s*$/; }
close (LL); close (LL);
system ("mv",$prtlocker."-tmp",$prtlocker); rename ($prtlocker."-tmp",$prtlocker);
} }
sub list_ports { sub list_ports {
@ -572,7 +572,7 @@ sub list_ports {
my %not_orphans = map { $_ => 0 } @searchspace; my %not_orphans = map { $_ => 0 } @searchspace;
foreach my $port (@searchspace) { foreach my $port (@searchspace) {
map { $not_orphans{$_} = 1 } split(/[ ,]+/, $DEPENDS{$port}); map { $not_orphans{$_} = 1 } split(/[ ,]+/, $DEPENDS{$port});
if ($odepends{soft} == 1) { if (($odepends{soft} == 1) and ($SOFTDEPS{$port})) {
map { $not_orphans{$_} = 1 } split(/[ ,]+/, $SOFTDEPS{$port}); map { $not_orphans{$_} = 1 } split(/[ ,]+/, $SOFTDEPS{$port});
} }
} }
@ -595,38 +595,45 @@ sub list_ports {
($odepends{tree} == 0) or print "$header\n"; ($odepends{tree} == 0) or print "$header\n";
our $indent=" "; our $height=0; our $indent=" "; our $height=0;
our $ind; our %seen; our @lineage; my @fosters=(); our $ind; our %seen; our @lineage; my @fosters=(); my @children=();
$ind = ($V_INST{$seed}) ? "[i]" : "[ ]"; $ind = ($V_INST{$seed}) ? "[i]" : "[ ]";
print "$ind $seed\n" if ($odepends{tree}==1); print "$ind $seed\n" if ($odepends{tree}==1);
$seen{$seed} = 1; $seen{$seed} = 1;
my @children = ($direction eq "fwd") ? split /[ ,]+/, $DEPENDS{$sseed}: if ($direction eq "rev") {
grep { " $DEPENDS{$_} " =~ / $sseed / } @searchspace; @children = grep { " $DEPENDS{$_} " =~ / $sseed / } @searchspace;
if ($odepends{soft}==1) { } elsif ($DEPENDS{$sseed}) {
@fosters = ($direction eq "fwd") ? @children = split /[ ,]+/, $DEPENDS{$sseed};
grep { ($V_INST{$_}) } split /[ ,]+/, $SOFTDEPS{$sseed}: }
grep { " $SOFTDEPS{$_} " =~ / $sseed / } @searchspace;
} if (($odepends{soft}==1) and ($direction eq "rev")) {
@fosters = grep { " $SOFTDEPS{$_} " =~ / $sseed / } @searchspace;
} elsif (($odepends{soft}==1) and ($SOFTDEPS{$sseed})) {
@fosters = grep { ($V_INST{$_}) } split /[ ,]+/, $SOFTDEPS{$sseed};
}
foreach my $sd (@children) { recurse_tree(0,$sd,$direction); } foreach my $sd (@children) { recurse_tree(0,$sd,$direction); }
foreach my $sd (@fosters) { recurse_tree(1,$sd,$direction); } foreach my $sd (@fosters) { recurse_tree(1,$sd,$direction); }
sub recurse_tree { sub recurse_tree {
my $greedy = shift; my $s = shift; my $direction=shift; my $greedy = shift; my $s = shift; my $direction=shift;
my %curdeps=(); my @optionals=();
my $ps = (($seen{$s}) and ($odepends{all} !=1)) ? "-->\n" : "\n"; my $ps = (($seen{$s}) and ($odepends{all} !=1)) ? "-->\n" : "\n";
$ind = ($V_INST{$s}) ? "[i]" : "[ ]"; $ind = ($V_INST{$s}) ? "[i]" : "[ ]";
$ind = (($ind eq "[i]") and ($greedy)) ? "[s]" : $ind; $ind = (($ind eq "[i]") and ($greedy)) ? "[s]" : $ind;
print $ind.(${indent}x(1+$height))."$s".$ps if ($odepends{tree}==1); print $ind.(${indent}x(1+$height))."$s".$ps if ($odepends{tree}==1);
return if (($seen{$s}) and ($odepends{all} !=1)); return if (($seen{$s}) and ($odepends{all} !=1));
$seen{$s} = 1; $seen{$s} = 1;
my %curdeps = ($direction eq "fwd") ? if ($direction eq "rev") {
map {$_ => 0} split /[ ,]+/, $DEPENDS{$s} : %curdeps = map {$_ => 0} grep { " $DEPENDS{$_} " =~ / $s / } @searchspace;
map {$_ => 0} grep { " $DEPENDS{$_} " =~ / $s / } @searchspace; } elsif ($DEPENDS{$s}) {
if ($odepends{soft} == 1) { %curdeps = map {$_ => 0} split /[ ,]+/, $DEPENDS{$s};
my @optionals = ($direction eq "fwd") ? }
grep { ($V_INST{$_}) } split /[ ,]+/, $SOFTDEPS{$s} : if (($odepends{soft}==1) and ($direction eq "rev")) {
grep { " $SOFTDEPS{$_} " =~ / $s / } @searchspace; @optionals = grep { " $SOFTDEPS{$_} " =~ / $s / } @searchspace;
map {$curdeps{$_} = 1} @optionals; } elsif (($odepends{soft}==1) and ($SOFTDEPS{$s})) {
@optionals = grep { ($V_INST{$_}) } split /[ ,]+/, $SOFTDEPS{$s};
} }
map {$curdeps{$_} = 1} @optionals;
foreach my $dc (keys %curdeps) { foreach my $dc (keys %curdeps) {
if (grep /^$dc$/, @lineage) { if (grep /^$dc$/, @lineage) {
@ -717,11 +724,11 @@ sub deporder { # returns a sorted list of packages required.
push(@treewalk, $s); $imark{$s}=1; push(@treewalk, $s); $imark{$s}=1;
# assemble the list of dependencies that must be visited next # assemble the list of dependencies that must be visited next
%curdeps = map { $_ => $greedy } split /[ ,]+/, $DEPENDS{$s}; (! $DEPENDS{$s}) or %curdeps = map { $_ => $greedy } split /[ ,]+/, $DEPENDS{$s};
# if the user toggles --softdeps, consider the optional dependencies # if the user toggles --softdeps, consider the optional dependencies
# that are already installed or are given on the command line # that are already installed or are given on the command line
if ($odepends{soft} == 1) { if (($odepends{soft} == 1) and ($SOFTDEPS{$s})) {
foreach (grep { ($V_INST{$_}) or ($given{$_}) } foreach (grep { ($V_INST{$_}) or ($given{$_}) }
split /[ ,]+/, $SOFTDEPS{$s}) { $curdeps{$_} = 1; } split /[ ,]+/, $SOFTDEPS{$s}) { $curdeps{$_} = 1; }
} }