Skip to content

Commit

Permalink
avoid infinit loop on multipart parse
Browse files Browse the repository at this point in the history
  • Loading branch information
sugama committed Jul 22, 2011
1 parent fa09bb2 commit 436d886
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Mojo/Content/MultiPart.pm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ sub _parse_multipart {
elsif (($self->{multi_state} || '') eq 'multipart_body') {
last unless $self->_parse_multipart_body($boundary);
}

else {
last;
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions t/mojo/content2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More tests => 1;

use Mojo::Content::MultiPart;
use Mojo::Message::Request;

local $SIG{ALRM} = sub { die "timeout\n" }; alarm 2;

my $req_seed = <<EOF;
GET /foo HTTP/1.0
Content-Type: multipart/mixed; boundary="abcdefg"
Content
--abcdefg--
EOF

$req_seed =~ s{\x0a}{\x0d\x0a}g;
my $req = Mojo::Message::Request->new;
$req->parse($req_seed);
$req->parse({});

is(1, 1, 'no infinit loop');

0 comments on commit 436d886

Please sign in to comment.