logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

preventing Mail::Message::Field::Structured::parse() infinite loop: msg#00000

Subject: preventing Mail::Message::Field::Structured::parse() infinite loop
Anthony D. Urso <anthonyu <at> killa.net> writes:

> Mail::Message::Field::Full::consumePhrase() refuses to consume this phrase,
> found in a real spam:
> 
> Content-Type: multipart/alternative;
>         boundary="--9arterial{403buzzing?575aeneid%903fungi\"
> 
> Since it isn't consumed, Mail::Message::Field::Structured::parse() goes
> into the obligatory busy-loop.
> 
> Removing the backslash works around the problem; however, I suspect that the
> regular expresion in consumePhrase needs to be altered, and something needs
> to be done about that parse() loop, it is far too easy to get it in a bad
> state. 
>
Hello,

I experienced the same problem recently while attempting to parse non-RFC
compliant header fields such as:

Content-Type: multipart/alternative;
   boundary="------------114140389345148";
   class-id=1:01111UNc8A4b9dckbCbHsQYebrYHUoYQ:668174

(Note the missing double quotes around the class-id attribute value.)

The patch below prevents Mail::Message::Field::Structured::parse() from hanging
on invalid header fields.  The die() call is admittedly a hack, but my app is
already calling parse() from within an eval block, so it's sufficient for my
purposes.  YMMV.

Regards,

Bryan


patch against v.2.064
-------------------------------------------------------------------------
--- Structured.pm.orig  2006-02-28 07:13:00.000000000 -0500
+++ Structured.pm       2006-04-05 11:02:21.027969184 -0400
@@ -90,7 +90,8 @@
         (undef, $string) = $self->consumeComment($string);
         $string =~ s/^\n//;
         (my $text, $string) = $self->consumePhrase($string);
-        $found .= $text if defined $text;
+        if(defined $text) { $found .= $text; }
+        else {   die "parse() failed on field '" . $self->name . "'"; }
     }

     if(length $found)
-------------------------------------------------------------------------






<Prev in Thread] Current Thread [Next in Thread>