Skip to content

Commit

Permalink
protect against load a dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 31, 2017
1 parent f2a113c commit 4e3db6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Plack/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ sub _load_sandbox {
package Plack::Sandbox::%s;
{
my $app = do $_file;
if ( !$app && ( my $error = $@ || $! )) { die $error; }
if ( !$app && ( my $error = $@ || $! || "returned invalid value.\n")) {
die $error;
}
$app;
}
END_EVAL
Expand Down
7 changes: 7 additions & 0 deletions t/Plack-Util/load.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ use Test::More;
unlike $@, qr/Died/;
}

{
eval { Plack::Util::load_psgi("t/Plack-Util/") };
# Perl 5.20+ gives "Did you try to load a directory",
# <=5.18 "No such file or directory"
like $@, qr/Error while loading/;
}

{
my $app = Plack::Util::load_psgi("t/Plack-Util/bin/findbin.psgi");
test_psgi $app, sub {
Expand Down

0 comments on commit 4e3db6e

Please sign in to comment.