Skip to content

Commit

Permalink
rewrite SCRIPT_FILENAME to full-path
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Dec 8, 2015
1 parent 73e32d6 commit 150bda5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion misc/fastcgi-cgi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Net::FastCGI::Constant qw(:common :type :flag :role :protocol_status);
use Net::FastCGI::IO qw(:all);
use Net::FastCGI::Protocol qw(:all);
use POSIX qw(:sys_wait_h);
use POSIX qw(:sys_wait_h getcwd);
use Socket qw(SOMAXCONN SOCK_STREAM);

my $master_pid = $$;
Expand All @@ -24,6 +24,7 @@
exit 0;
};

my $base_dir = getcwd;
chdir "/"
or die "failed to chdir to /:$!";

Expand Down Expand Up @@ -89,6 +90,8 @@ sub handle_connection {
my $env = parse_params($params);
die "SCRIPT_FILENAME not defined"
unless $env->{SCRIPT_FILENAME};
$env->{SCRIPT_FILENAME} = "$base_dir/$env->{SCRIPT_FILENAME}"
if $env->{SCRIPT_FILENAME} !~ m{^/};

# accumulate FCGI_STDIN
while (1) {
Expand Down
5 changes: 4 additions & 1 deletion share/h2o/fastcgi-cgi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use Net::FastCGI;
use Net::FastCGI::Constant qw(:common :type :flag :role :protocol_status);
use Net::FastCGI::IO qw(:all);
use Net::FastCGI::Protocol qw(:all);
use POSIX qw(:sys_wait_h);
use POSIX qw(:sys_wait_h getcwd);
use Socket qw(SOMAXCONN SOCK_STREAM);

my $master_pid = $$;
Expand All @@ -85,6 +85,7 @@ $SIG{TERM} = sub {
exit 0;
};

my $base_dir = getcwd;
chdir "/"
or die "failed to chdir to /:$!";

Expand Down Expand Up @@ -150,6 +151,8 @@ sub handle_connection {
my $env = parse_params($params);
die "SCRIPT_FILENAME not defined"
unless $env->{SCRIPT_FILENAME};
$env->{SCRIPT_FILENAME} = "$base_dir/$env->{SCRIPT_FILENAME}"
if $env->{SCRIPT_FILENAME} !~ m{^/};

# accumulate FCGI_STDIN
while (1) {
Expand Down

0 comments on commit 150bda5

Please sign in to comment.