possible bug in Empty() method of MessageBatch.pm

Jules Field MailScanner at ecs.soton.ac.uk
Sat Jul 31 17:33:23 IST 2010


I'm afraid I disagree with you.
The "each" iterator will get reset each time this function is called.
As soon as it finds one which is not deleted, it returns 0.
Only if it finds that all the messages are deleted will it ever reach 
the "return 1" statement.

Your version will achieve the same end result but be slower as you 
insist on going through every message in the batch before returning 
anything. My version bails out as soon as it knows the result is false 
(i.e. as soon as it found one message which is not deleted).

On 20/07/2010 05:54, Timofey Kutergin wrote:
> Hi all,
> here is possible bug in Empty() method:
>
> # Return true if all the messages in the batch are deleted!
> # Return false otherwise.
> sub Empty {
>   my $this = shift;
>
>   my($id, $message);
>   while(($id,$message) = each %{$this->{messages}}) {
>     return 0 unless $message->{deleted};
>   }
>   return 1;
> }
>
> Problem is that if this function does return 0, it does not reset 
> "each" iterator so next loop around $this->{messages} will continue 
> with the same position.
> This may manifest itself in phishing not always detected since loop in 
> ScanBatch() in SweepContent.pm exits due to not resetting iterator.
>
> From my point of view, more proper code would be:
>
> # Return true if all the messages in the batch are deleted!
> # Return false otherwise.
> sub Empty {
>   my $this = shift;
>   my $res = 1;
>
>   my($id, $message);
>   while(($id,$message) = each %{$this->{messages}}) {
>     $res = 0 unless $message->{deleted};
>   }
>   return $res;
> }
> So iterator resets itself after completing cycle
>
> Am I terribly wrong?
>
> Regards
> Timofey

Jules

-- 
Julian Field MEng CITP CEng
www.MailScanner.info
Buy the MailScanner book at www.MailScanner.info/store

Need help customising MailScanner?
Contact me!
Need help fixing or optimising your systems?
Contact me!
Need help getting you started solving new requirements from your boss?
Contact me!

PGP footprint: EE81 D763 3DB0 0BFD E1DC 7222 11F6 5947 1415 B654
Follow me at twitter.com/JulesFM


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the MailScanner mailing list