X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FCGIBin.pm;h=e332ef47f818f436b8e5dc9032ac6949665c50aa;hb=e889d52612ce3eaa1fb64150f76543aa03cc6253;hp=e0ca62c1c84ffe5ad74e74bac107c1b3db78e33a;hpb=63283669a7954f748cbf54305094f2570390f325;p=catagits%2FCatalyst-Controller-WrapCGI.git diff --git a/lib/Catalyst/Controller/CGIBin.pm b/lib/Catalyst/Controller/CGIBin.pm index e0ca62c..e332ef4 100644 --- a/lib/Catalyst/Controller/CGIBin.pm +++ b/lib/Catalyst/Controller/CGIBin.pm @@ -14,6 +14,7 @@ use Symbol 'gensym'; use List::MoreUtils 'any'; use IO::File (); use Carp; +use File::Temp 'tempfile'; use namespace::clean -except => 'meta'; @@ -23,11 +24,11 @@ Catalyst::Controller::CGIBin - Serve CGIs from root/cgi-bin =head1 VERSION -Version 0.018 +Version 0.021 =cut -our $VERSION = '0.018'; +our $VERSION = '0.021'; =head1 SYNOPSIS @@ -208,18 +209,28 @@ L. sub is_perl_cgi { my ($self, $cgi) = @_; - my $shebang = IO::File->new($cgi)->getline; + my (undef, $tempfile) = tempfile; - return 0 if $shebang !~ /perl/ && $cgi !~ /\.pl\z/; + my $pid = fork; + die "Cannot fork: $!" unless defined $pid; - my $taint_check = $shebang =~ /-T/ ? '-T' : ''; + if ($pid) { + waitpid $pid, 0; + my $errors = IO::File->new($tempfile)->getline; + unlink $tempfile; + return $errors ? 0 : 1; + } + # child + local *NULL; open NULL, '>', File::Spec->devnull; - my $pid = open3(gensym, '&>NULL', '&>NULL', "$^X $taint_check -c $cgi"); - close NULL; - waitpid $pid, 0; + open STDOUT, '>&', \*NULL; + open STDERR, '>&', \*NULL; + close STDIN; - $? >> 8 == 0 + do $cgi; + IO::File->new(">$tempfile")->print($@); + exit; } =head2 wrap_perl_cgi @@ -313,10 +324,12 @@ __PACKAGE__->meta->make_immutable; L, L, L, L, L -=head1 AUTHORS +=head1 AUTHOR Rafael Kitover, C<< >> +=head1 CONTRIBUTORS + Hans Dieter Pearcey, C<< >> =head1 BUGS