Subject: | Crash when multipart/form-data has non-file parameters |
Crashes when:
- POST with multipart/form-data
- form has non-file parameters
- body_parameters called from plugin
- body_parameters called before maybe::next::method.
Tested on Catalyst 5.90112
1) Create empty app: catalyst.pl MyApp
2) Add a plugin. Here is the diff:
=====
diff --git a/MyApp/lib/MyApp.pm b/MyApp/lib/MyApp.pm
index 2d9c4cb..98dfd0b 100644
--- a/MyApp/lib/MyApp.pm
+++ b/MyApp/lib/MyApp.pm
@@ -20,6 +20,7 @@ use Catalyst qw/
-Debug
ConfigLoader
Static::Simple
+ +MyPlugin
/;
extends 'Catalyst';
=====
and plugin code:
====
package MyPlugin;
use strict;
use warnings;
sub prepare_parameters {
my $c = shift;
my $tmp = $c->request->body_parameters;
$c->maybe::next::method(@_);
}
1;
===
3) run
$ echo 1 > somefile.txt
$ curl -vv --form upload=@somefile.txt --form name=value http://localhost:3000/
and you'll get "Bad request":
* About to connect() to localhost port 3000 (#0)
* Trying 127.0.0.1... connected
Show quoted text
> POST / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:3000
> Accept: */*
> Content-Length: 292
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------9cef9092c998
>
* Done waiting for 100-continue
* HTTP 1.0, assume close after body
< HTTP/1.0 400 Bad Request
< Date: Tue, 16 Aug 2016 07:17:29 GMT
< Server: HTTP::Server::PSGI
< Content-Type: text/plain; charset=UTF-8
< X-Catalyst: 5.90112
< Content-Length: 11
<
* Closing connection #0
Bad Request
And the following output:
.------------------------------------------------------------+-----------.
| Action | Time |
+------------------------------------------------------------+-----------+
'------------------------------------------------------------+-----------'
[error] Caught exception in engine "Can't call method "config" on an undefined value at /usr/local/share/perl/5.14.2/Catalyst/Request.pm line 335."