Subject: | Incorrect searchlist duplication removal in Net::DNS::Resolver::Win32 |
There is a bug in Win32.pm around lines 102-117. Here is the relevant part:
102 # fix devolution if configured, and simultaneously make
sure no dups (but keep the order)
103 my $i = 0;
104 my %h;
105 foreach my $entry (split(m/[\s,]+/, $searchlist)) {
106 $h{$entry} = $i++;
114 }
115 my @a;
116 $a[$h{$_}] = $_ foreach (keys %h);
117 $defaults->{'searchlist'} = \@a;
As the comment says, I understand the idea is to strip any duplicates from $searchlist while maintaining its order. So if
$searchlist = "a b a a c ";
I would expect to get
@a = ["a", "b", "c" ]
but instead I get
@a = [undef, "b", undef, "a", "c"]
Not only is the order wrong, but the intervening undefined entries may cause problems otherwhere in the code.
Attached is a fix that removes duplicates in the standard way, as done just below the part I quoted, in lines 122-127.
--- Win32.pm.orig 2004-08-12 08:48:00.000000000 +0300
+++ Win32.pm.fixed 2005-03-17 16:19:03.313720000 +0200
@@ -100,20 +100,20 @@
my $usedevolution = $keys{'UseDomainNameDevolution'}->[2];
if ($searchlist) {
# fix devolution if configured, and simultaneously make sure no dups (but keep the order)
- my $i = 0;
+ my @a;
my %h;
foreach my $entry (split(m/[\s,]+/, $searchlist)) {
- $h{$entry} = $i++;
+ push(@a, $entry) unless $h{$entry};
+ $h{$entry} = 1;
if ($usedevolution) {
# as long there's more than two pieces, cut
while ($entry =~ m#\..+\.#) {
$entry =~ s#^[^\.]+\.(.+)$#$1#;
- $h{$entry} = $i++;
+ push(@a, $entry) unless $h{$entry};
+ $h{$entry} = 1;
}
}
}
- my @a;
- $a[$h{$_}] = $_ foreach (keys %h);
$defaults->{'searchlist'} = \@a;
}