fix: use local $_ before while(<>) loops

This closes a range of bugs that can happen if a function using $_ implicitly
in a while is called in a grep {} or map {} which also uses $_
This commit is contained in:
Stéphane Lesimple 2021-06-29 17:41:17 +00:00 committed by Stéphane Lesimple
parent 2193ee487d
commit b942131092
3 changed files with 3 additions and 0 deletions

View file

@ -307,6 +307,7 @@ sub sys_delmemberfromgroup {
# manually patching /etc/group... eew :(
my $contents;
if (open(my $fh, '<', '/etc/group')) {
local $_ = undef;
while (<$fh>) {
if (/^\Q$group\E:/) {
s/([:,])\Q$user\E(?:,|$)/$1/;

View file

@ -124,6 +124,7 @@ sub get_hashes_list {
my %metadata;
if (open(my $metadatafd, '<', "$currentname.metadata")) {
local $_ = undef;
while (<$metadatafd>) {
chomp;
m{^([A-Z0-9_-]+)=(.+)$} or next;

View file

@ -361,6 +361,7 @@ sub get_ssh_pub_key_info {
$shortfp =~ s/^.{12}//;
#print "looking for shortfingerprint=$shortfp...\n";
local $_ = undef;
while (<$fh_blacklist>) {
/^\Q$shortfp\E$/ or next;
close($fh_blacklist);