Skip to content

Commit cb6fed5

Browse files
author
Torsten Förtsch
committed
use APR::Finfo instead of Perls stat() in ModPerl::RegistryCooker
git-svn-id: https://svn.apache.org/repos/asf/perl/modperl/trunk@1451907 13f79535-47bb-0310-9956-ffa450edef68
1 parent 686ed00 commit cb6fed5

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Also refer to the Apache::Test changes log file, at Apache-Test/Changes
1212

1313
=item 2.0.8-dev
1414

15+
use APR::Finfo instead of Perl's stat() in ModPerl::RegistryCooker to
16+
generate HTTP code 404 even if the requested filename contains newlines
17+
[Torsten]
18+
1519
Remove all uses of deprecated core perl symbols. [Steve Hay]
1620

1721
Add branch release tag to 'make tag' target. [Phred]

ModPerl-Registry/lib/ModPerl/RegistryCooker.pm

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use Apache2::Log ();
3636
use Apache2::Access ();
3737

3838
use APR::Table ();
39+
use APR::Finfo ();
3940
use APR::Status ();
4041

4142
use ModPerl::Util ();
@@ -45,6 +46,7 @@ use File::Spec::Functions ();
4546
use File::Basename ();
4647

4748
use Apache2::Const -compile => qw(:common &OPT_EXECCGI);
49+
use APR::Const -compile => qw(FILETYPE_REG);
4850
use ModPerl::Const -compile => 'EXIT';
4951

5052
unless (defined $ModPerl::Registry::MarkLine) {
@@ -256,9 +258,10 @@ sub can_compile {
256258
my $self = shift;
257259
my $r = $self->{REQ};
258260

259-
return Apache2::Const::DECLINED if -d $r->my_finfo;
261+
return Apache2::Const::DECLINED
262+
unless $r->finfo->filetype==APR::Const::FILETYPE_REG;
260263

261-
$self->{MTIME} = -M _;
264+
$self->{MTIME} = $r->finfo->mtime;
262265

263266
if (!($r->allow_options & Apache2::Const::OPT_EXECCGI)) {
264267
$r->log_error("Options ExecCGI is off in this directory",
@@ -485,9 +488,9 @@ sub is_cached {
485488
# wasn't modified
486489
sub should_compile_if_modified {
487490
my $self = shift;
488-
$self->{MTIME} ||= -M $self->{REQ}->my_finfo;
491+
$self->{MTIME} ||= $self->{REQ}->finfo->mtime;
489492
!($self->is_cached &&
490-
$self->cache_table->{ $self->{PACKAGE} }{mtime} <= $self->{MTIME});
493+
$self->cache_table->{ $self->{PACKAGE} }{mtime} == $self->{MTIME});
491494
}
492495

493496
# return false if the package is cached already
@@ -780,14 +783,5 @@ sub uncache_myself {
780783
}
781784

782785

783-
# XXX: should go away when finfo() is ported to 2.0 (don't want to
784-
# depend on compat.pm)
785-
sub Apache2::RequestRec::my_finfo {
786-
my $r = shift;
787-
stat $r->filename;
788-
\*_;
789-
}
790-
791-
792786
1;
793787
__END__

ModPerl-Registry/lib/ModPerl/RegistryLoader.pm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use ModPerl::RegistryCooker ();
2222
use Apache2::ServerUtil ();
2323
use Apache2::Log ();
2424
use APR::Pool ();
25+
use APR::Finfo ();
26+
use APR::Const -compile=>qw(FINFO_NORM);
2527

2628
use Carp;
2729
use File::Spec ();
@@ -110,8 +112,11 @@ sub handler {
110112

111113
sub get_server_name { return $_[0]->{virthost} if exists $_[0]->{virthost} }
112114
sub filename { shift->{filename} }
113-
sub status { Apache2::Const::HTTP_OK }
114-
sub my_finfo { shift->{filename} }
115+
sub status { Apache2::Const::HTTP_OK }
116+
sub pool { shift->{pool}||=APR::Pool->new() }
117+
sub finfo { $_[0]->{finfo}||=APR::Finfo::stat($_[0]->{filename},
118+
APR::Const::FINFO_NORM,
119+
$_[0]->pool); }
115120
sub uri { shift->{uri} }
116121
sub path_info {}
117122
sub allow_options { Apache2::Const::OPT_EXECCGI } #will be checked again at run-time
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!perl
2+
3+
use strict;
4+
use warnings FATAL => 'all';
5+
6+
use Apache::Test;
7+
use Apache::TestUtil;
8+
use Apache::TestRequest qw(GET_RC);
9+
10+
plan tests => 1, need 'mod_alias.c';
11+
12+
{
13+
# this used to result in 500 due to a combination of Perl warning about
14+
# a newline in the filename passed to stat() and our
15+
# use warnings FATAL=>'all'
16+
17+
t_client_log_error_is_expected();
18+
my $url = '/registry/file%0dwith%0anl%0d%0aand%0a%0dcr';
19+
ok t_cmp GET_RC($url), 404, 'URL with \\r and \\n embedded';
20+
}

ModPerl-Registry/t/cgi-bin/closure.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!perl -w
22

33
BEGIN {
4-
use Apache::TestUtil;
4+
use Apache::TestUtil qw/t_server_log_warn_is_expected/;
55
t_server_log_warn_is_expected();
66
}
77

@@ -16,7 +16,7 @@ BEGIN
1616
counter();
1717

1818
sub counter {
19-
#warn "$$";
19+
#warn "$$: counter=$counter";
2020
print ++$counter;
2121
}
2222

0 commit comments

Comments
 (0)