Skip to content

Commit

Permalink
avoid the potential for crazy backtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Oct 12, 2015
1 parent 7d06e0d commit 8b6843d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
Revision history for Perl extension Email::Simple

{{$NEXT}}
- avoid opportunity for pathological backtracking behavior on
malformed messages

2.208 2015-07-20 20:34:04-04:00 America/New_York
- same as v2.207
Expand Down
12 changes: 8 additions & 4 deletions lib/Email/Simple.pm
Expand Up @@ -109,14 +109,18 @@ sub _split_head_from_body {
my ($self, $text_ref) = @_;

# For body/header division, see RFC 2822, section 2.1
my $crlf = $self->__crlf_re;
#
# Honestly, are we *ever* going to have LFCR messages?? -- rjbs, 2015-10-11
my $re = qr{\x0a\x0d\x0a\x0d|\x0d\x0a\x0d\x0a|\x0d\x0d|\x0a\x0a};

if ($$text_ref =~ /(?:.*?($crlf))\1/gsm) {
return (pos($$text_ref), $1);
if ($$text_ref =~ /($re)/gsm) {
my $crlf = substr $1, 0, length($1)/2;
return (pos($$text_ref), $crlf);
} else {

# The body is, of course, optional.
$$text_ref =~ /($crlf)/gsm;
my $re = $self->__crlf_re;
$$text_ref =~ /($re)/gsm;
return (undef, ($1 || "\n"));
}
}
Expand Down

0 comments on commit 8b6843d

Please sign in to comment.