https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6506

           Summary: Modifying a list while traversing it with a foreach
           Product: Spamassassin
           Version: 3.3.1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Libraries
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Found the following code section in Plugin/DNSEval.pm:

  foreach my $ip (@ips) {
    last if !$trusted->contains_ip($ip);
    shift @ips;  # remove trusted hosts from beginning
  }

According to perl docs, modifying a list while traversing it
can give unpredictable results, so this clearly looks like a bug
which will strike back some day, if not already (depending on
a version of perl).

$ man perlsyn
Foreach Loops
  If any part of LIST is an array, foreach will get very confused
  if you add or remove elements within the loop body, for example
  with splice. So don't do that.


So what is it supposed to do anyway?
Suggesting the following replacement:

  # remove trusted hosts from beginning
  while (@ips && $trusted->contains_ip($ips[0])) { shift @ips }

-- 
Configure bugmail: 
https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Reply via email to