Skip to content

Commit 6fa9824

Browse files
committed
protect against load a dir
1 parent f2a113c commit 6fa9824

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/Plack/Util.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sub FALSE() { !TRUE }
1111

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

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

120-
return eval sprintf <<'END_EVAL', $_package;
121+
return eval sprintf <<'END_EVAL', $_package, LOAD_ERROR;
121122
package Plack::Sandbox::%s;
122123
{
123124
my $app = do $_file;
124-
if ( !$app && ( my $error = $@ || $! )) { die $error; }
125+
if ( !$app && ( my $error = $@ || $! || "%s" )) { die $error; }
125126
$app;
126127
}
127128
END_EVAL

t/Plack-Util/load.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ use Test::More;
4545
unlike $@, qr/Died/;
4646
}
4747

48+
{
49+
eval { Plack::Util::load_psgi("t/Plack-Util/") };
50+
# Perl 5.20+ gives "Did you try to load a directory",
51+
# <=5.18 "No such file or directory"
52+
like $@, qr/Error while loading/;
53+
}
54+
4855
{
4956
my $app = Plack::Util::load_psgi("t/Plack-Util/bin/findbin.psgi");
5057
test_psgi $app, sub {

0 commit comments

Comments
 (0)