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 30, 2017
1 parent f2a113c commit 42efc73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Plack/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sub FALSE() { !TRUE }

# there does not seem to be a relevant RT or perldelta entry for this
use constant _SPLICE_SAME_ARRAY_SEGFAULT => $] < '5.008007';
use constant LOAD_ERROR => "Unknown error. Did you try to load a directory?\n";

sub load_class {
my($class, $prefix) = @_;
Expand Down Expand Up @@ -117,11 +118,11 @@ sub _load_sandbox {
local $0 = $_file; # so FindBin etc. works
local @ARGV = (); # Some frameworks might try to parse @ARGV

return eval sprintf <<'END_EVAL', $_package;
return eval sprintf <<'END_EVAL', $_package, LOAD_ERROR;
package Plack::Sandbox::%s;
{
my $app = do $_file;
if ( !$app && ( my $error = $@ || $! )) { die $error; }
if ( !$app && ( my $error = $@ || $! || "%s" )) { die $error; }
$app;
}
END_EVAL
Expand Down
5 changes: 5 additions & 0 deletions t/Plack-Util/load.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ use Test::More;
unlike $@, qr/Died/;
}

{
eval { Plack::Util::load_psgi("t/Plack-Util/") };
like $@, qr/Did you try to load a directory/;
}

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

0 comments on commit 42efc73

Please sign in to comment.