Skip to content

protect against loading a dir - do $dir no set $@ or $! #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment accurate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was highly surprised as well. See Travis's results on the previous version of this before I force-pushed this over the top: https://travis-ci.org/plack/Plack/builds/323431062

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed perl 5.18 reports "No such file or directory" given a directory as its argument for do. I think it's worth reporting to upstream (p5p) or make sure if this was an intentional change, since the previous behavior was more useful.

Copy link
Author

@mohawk2 mohawk2 Dec 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead! In the meantime, unless there will be further releases of 5.20 etc, it seems like this is a useful change. Do you require changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well since you discovered it you go ahead and report it :)

this will give the same error message for a valid perl code that failed to return from .psgi. You're right that a false value is not a right PSGI application, but the error message seems misleading to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will adjust it now!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it will just report returned invalid value., which seems to me Ok when appended to the existing Error while loading $_file:?

like $@, qr/Error while loading/;
}

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