From 4e3db6e7da4a39e350a6af01c064549066b7914e Mon Sep 17 00:00:00 2001 From: Ed J Date: Sat, 30 Dec 2017 22:26:42 +0000 Subject: [PATCH] protect against load a dir --- lib/Plack/Util.pm | 4 +++- t/Plack-Util/load.t | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Plack/Util.pm b/lib/Plack/Util.pm index a0d4e39f2..ebee0b3f7 100644 --- a/lib/Plack/Util.pm +++ b/lib/Plack/Util.pm @@ -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 diff --git a/t/Plack-Util/load.t b/t/Plack-Util/load.t index 0b69d8bf8..3f799958d 100644 --- a/t/Plack-Util/load.t +++ b/t/Plack-Util/load.t @@ -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 {