Bug#849298: libconfig-inifiles-perl: Infinite loop when "each" is used

Niko Tyni ntyni at debian.org
Sun Dec 25 20:45:34 UTC 2016


Control: tag -1 patch

On Sun, Dec 25, 2016 at 12:24:45AM +0100, Johannes Schauer wrote:
> Package: libconfig-inifiles-perl
> Version: 2.94-1
> Severity: normal

> use Config::IniFiles;
> tie (my %ini, 'Config::IniFiles', -file=>"test.ini");
> foreach my $s (keys %ini) {
>     while (my ($k,$v) = each %{$ini{$s}}) {
>         print("$s $k $v\n");
>     }
> }

> The result will be an infinite loop printing "foo bar baz".

Thanks for the report.

What is happening is that every time $ini{$s} is evaluated,
Config::IniFiles::FETCH() creates a new Config::IniFiles::_section tied
hash that has its own each() iterator.

A workaround is to do something like

  foreach my $s (@k) {
      my $i = $ini{$s};
      while (my ($k,$v) = each %$i) {
          print("$s $k $v\n");
      }
  }
 
but I'm attaching a patch that seems to fix this without breaking any
existing tests.
-- 
Niko Tyni   ntyni at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Reuse-Config-IniFiles-_section-hashes-in-Config-IniF.patch
Type: text/x-diff
Size: 2097 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/attachments/20161225/b3fbca69/attachment.patch>


More information about the pkg-perl-maintainers mailing list