Просмотр исходного кода

scripts: Localize $_ in functions with while (<$fh>) style loops

This way we make sure we don't affect the $_ value for the caller,
in case it was being used.
Guillem Jover лет назад: 12
Родитель
Сommit
7e7156bee2

+ 1 - 0
debian/changelog

@@ -12,6 +12,7 @@ dpkg (1.17.7) UNRELEASED; urgency=low
       dpkg-maintscript-helper(1). Closes: #739388
   * Use exit instead of return to exit a subshell in dpkg-maintscript-helper.
     Thanks to Richard Levitte <richard@levitte.org>. Closes: #738957
+  * Localize $_ in Perl functions with while (<$fh>) style loops.
 
   [ Updated dpkg translations ]
   * German (Sven Joachim).

+ 2 - 0
scripts/Dpkg/BuildFlags.pm

@@ -301,6 +301,8 @@ $source is the origin recorded for any build flag set or modified.
 
 sub update_from_conffile {
     my ($self, $file, $src) = @_;
+    local $_;
+
     return unless -e $file;
     open(my $conf_fh, '<', $file) or syserr(_g('cannot read %s'), $file);
     while (<$conf_fh>) {

+ 1 - 0
scripts/Dpkg/Changelog/Debian.pm

@@ -81,6 +81,7 @@ sub parse {
     my $entry = Dpkg::Changelog::Entry::Debian->new();
     my @blanklines = ();
     my $unknowncounter = 1; # to make version unique, e.g. for using as id
+    local $_;
 
     while (<$fh>) {
 	chomp;

+ 2 - 0
scripts/Dpkg/Changelog/Parse.pm

@@ -102,6 +102,8 @@ sub changelog_parse {
 
     # Extract the format from the changelog file if possible
     unless($force or ($changelogfile eq '-')) {
+	local $_;
+
 	open(my $format_fh, '-|', 'tail', '-n', '40', $changelogfile)
 	    or syserr(_g('cannot create pipe for %s'), 'tail');
 	while (<$format_fh>) {

+ 2 - 0
scripts/Dpkg/Conf.pm

@@ -95,6 +95,8 @@ Parse options from a file handle. Return the number of options parsed.
 sub parse {
     my ($self, $fh, $desc) = @_;
     my $count = 0;
+    local $_;
+
     while (<$fh>) {
 	chomp;
 	s/^\s+//; s/\s+$//;   # Strip leading/trailing spaces

+ 1 - 0
scripts/Dpkg/Control/HashCore.pm

@@ -186,6 +186,7 @@ sub parse {
     my $parabody = 0;
     my $cf; # Current field
     my $expect_pgp_sig = 0;
+    local $_;
 
     while (<$fh>) {
 	s/\s*\n$//;

+ 2 - 0
scripts/Dpkg/Shlibs.pm

@@ -83,6 +83,8 @@ parse_ldso_conf('/etc/ld.so.conf') if -e '/etc/ld.so.conf';
 my %visited;
 sub parse_ldso_conf {
     my $file = shift;
+    local $_;
+
     open my $fh, '<', $file or syserr(_g('cannot open %s'), $file);
     $visited{$file}++;
     while (<$fh>) {

+ 2 - 0
scripts/Dpkg/Shlibs/Objdump.pm

@@ -93,6 +93,8 @@ sub has_object {
 	    return $format{$file};
 	} else {
 	    my ($output, %opts, $pid, $res);
+	    local $_;
+
 	    if ($objdump ne 'objdump') {
 		$opts{error_to_file} = '/dev/null';
 	    }

+ 2 - 0
scripts/Dpkg/Source/Package/V3/Bzr.pm

@@ -112,6 +112,8 @@ sub do_build {
     my $old_cwd = getcwd();
     chdir($dir) or syserr(_g("unable to chdir to `%s'"), $dir);
 
+    local $_;
+
     # Check for uncommitted files.
     # To support dpkg-source -i, remove any ignored files from the
     # output of bzr status.

+ 3 - 1
scripts/Dpkg/Source/Package/V3/Git.pm

@@ -121,7 +121,9 @@ sub do_build {
     open(my $git_ls_files_fh, '-|', 'git', 'ls-files', '--modified', '--deleted',
          '-z', '--others', @ignores) or subprocerr('git ls-files');
     my @files;
-    { local $/ = "\0";
+    {
+      local $_;
+      local $/ = "\0";
       while (<$git_ls_files_fh>) {
           chomp;
           if (! length $diff_ignore_regex ||

+ 2 - 0
scripts/Dpkg/Source/Patch.pm

@@ -107,6 +107,8 @@ sub add_diff_file {
     # Check diff and write it in patch file
     my $difflinefound = 0;
     my $binary = 0;
+    local $_;
+
     while (<$diffgen>) {
         if (m/^(?:binary|[^-+\@ ].*\bdiffer\b)/i) {
             $binary = 1;

+ 2 - 0
scripts/Dpkg/Substvars.pm

@@ -169,6 +169,8 @@ the filehandle in error messages.
 
 sub parse {
     my ($self, $fh, $varlistfile) = @_;
+    local $_;
+
     binmode($fh);
     while (<$fh>) {
 	next if m/^\s*\#/ || !m/\S/;