Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: Dev

$r->location bug

 

 

ModPerl dev RSS feed   Index | Next | Previous | View Threaded


torsten.foertsch at gmx

Feb 18, 2008, 1:00 PM

Post #1 of 7 (2398 views)
Permalink
$r->location bug

Hi,

modperl_config_dir_create begins with these lines:

void *modperl_config_dir_create(apr_pool_t *p, char *dir)
{
modperl_config_dir_t *dcfg = modperl_config_dir_new(p);

dcfg->location = dir;

While dcfg is created anew the dir pointer is simply stored. This means the
lifetime of dcfg may exceed the lifetime of the dir pointer. In fact I have
found the bug because I got rubbish from $r->location in the response phase
after the response handler was added via $r->add_config in the map2storage
phase.

Here is a patch and a test case.

Torsten

Index: src/modules/perl/modperl_config.c
===================================================================
--- src/modules/perl/modperl_config.c (revision 35)
+++ src/modules/perl/modperl_config.c (working copy)
@@ -20,7 +20,7 @@
{
modperl_config_dir_t *dcfg = modperl_config_dir_new(p);

- dcfg->location = dir;
+ dcfg->location = dir ? apr_pstrdup(p, dir) : NULL;

MP_TRACE_d(MP_FUNC, "dir %s", dir);

Index: t/response/TestAPI/add_config.pm
===================================================================
--- t/response/TestAPI/add_config.pm (revision 31)
+++ t/response/TestAPI/add_config.pm (working copy)
@@ -59,6 +59,14 @@
};
$r->pnotes(followsymlinks => "$@");

+ eval {
+ my $path="/a/path/to/somewhere";
+ $r->add_config(['PerlResponseHandler '.__PACKAGE__], -1, $path);
+ # now overwrite the path in place to see if the location pointer
+ # is really copied: see modperl_config_dir_create
+ $path=~tr[a-z][n-za-m];
+ };
+
return Apache2::Const::DECLINED;
}

@@ -83,7 +91,7 @@
my ($self, $r) = @_;
my $cf = $self->get_config($r->server);

- plan $r, tests => 8;
+ plan $r, tests => 9;

ok t_cmp $r->pnotes('add_config1'), qr/.+\n/;
ok t_cmp $r->pnotes('add_config2'), (APACHE22 ? qr/.+\n/ : '');
@@ -103,6 +111,8 @@
my $opts = APACHE22 ? Apache2::Const::OPT_SYM_LINKS : $expect;
ok t_cmp $r->allow_override_opts, $opts;

+ ok t_cmp $r->location, '/a/path/to/somewhere';
+
return Apache2::Const::OK;
}

@@ -118,7 +128,6 @@
<Directory @DocumentRoot@>
AllowOverride All
</Directory>
- PerlResponseHandler TestAPI::add_config
PerlMapToStorageHandler TestAPI::add_config::map2storage
PerlFixupHandler TestAPI::add_config::fixup
</VirtualHost>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


torsten.foertsch at gmx

Feb 20, 2008, 2:38 AM

Post #2 of 7 (2260 views)
Permalink
Re: $r->location bug [In reply to]

On Mon 18 Feb 2008, Torsten Foertsch wrote:
> Here is a patch and a test case.

Forget the patch. It fixes the wrong place. The only other directive (that I
know of) that uses the location path ProxyPassReverse also assumes that the
pointer is valid for the whole request.

So the correct place to approach is our $r->add_config.

Torsten
Attachments: location_bug.patch (1.85 KB)


fred at taperfriendlymusic

Feb 21, 2008, 12:18 PM

Post #3 of 7 (2264 views)
Permalink
Re: $r->location bug [In reply to]

> On Mon 18 Feb 2008, Torsten Foertsch wrote:
>> Here is a patch and a test case.
>
> Forget the patch. It fixes the wrong place. The only other directive (that
> I
> know of) that uses the location path ProxyPassReverse also assumes that
> the
> pointer is valid for the whole request.
>
> So the correct place to approach is our $r->add_config.

Just tried this patch:

patching file src/modules/perl/modperl_config.c
Hunk #1 succeeded at 607 with fuzz 1 (offset -17 lines).

My modperl_config.c is at revision 29971 - do you have an old version of
this file?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


gozer at ectoplasm

Feb 21, 2008, 10:32 PM

Post #4 of 7 (2248 views)
Permalink
Re: $r->location bug [In reply to]

Torsten Foertsch wrote:
> On Mon 18 Feb 2008, Torsten Foertsch wrote:
>> Here is a patch and a test case.
>
> Forget the patch. It fixes the wrong place. The only other directive (that I
> know of) that uses the location path ProxyPassReverse also assumes that the
> pointer is valid for the whole request.
>
> So the correct place to approach is our $r->add_config.

I don't understand how this is fixing the problem cleanly. What seems
to be the culprit is modperl_config_insert() keeping a hold of the path
longer than it might live. Wouldn't this patch solve the problem as
well, and more directly ?

Index: src/modules/perl/modperl_config.c
===================================================================
--- src/modules/perl/modperl_config.c (revision 629347)
+++ src/modules/perl/modperl_config.c (working copy)
@@ -518,7 +518,7 @@
parms.limited = -1;
parms.server = s;
parms.override = override;
- parms.path = path;
+ parms.path = apr_pstrdup(p, path);
parms.pool = p;
#ifdef MP_HTTPD_HAS_OVERRIDE_OPTS
if (override_options == MP_HTTPD_OVERRIDE_OPTS_UNSET) {

--
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
Attachments: signature.asc (0.24 KB)


torsten.foertsch at gmx

Feb 22, 2008, 2:38 AM

Post #5 of 7 (2249 views)
Permalink
Re: $r->location bug [In reply to]

On Fri 22 Feb 2008, Philippe M. Chiasson wrote:
> -    parms.path = path;
> +    parms.path = apr_pstrdup(p, path);

Yes, Philippe, you are right.

In current modperl there are 3 ways to get to modperl_config_insert():

- $r->add_config via modperl_config_insert_request
- $s->add_config via modperl_config_insert_server
- $parms->add_config via modperl_config_insert_parms

Since $parms->path is read-only and modperl_config_insert_server passes a NULL
as path there is only one way to have a custom path passed to
modperl_config_insert, modperl_config_insert_request. So patching
$r->add_config only would be sufficient, as well.

Nevertheless, fixing it in modperl_config_insert is probably the best way
regarding future changes.

Torsten

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


torsten.foertsch at gmx

Feb 22, 2008, 4:45 AM

Post #6 of 7 (2267 views)
Permalink
Re: $r->location bug [In reply to]

On Thu 21 Feb 2008, Fred Moyer wrote:
> patching file src/modules/perl/modperl_config.c
> Hunk #1 succeeded at 607 with fuzz 1 (offset -17 lines).

I am working with the threading branch. So there may be an offset. Also, some
time ago I had to split up a jumbo patch. Since the bits built up on top of
one another I found it really hard to do it without write permission to the
SVN. The first part could be produced by svn diff. But then I had to wait
until someone had checked that in to do the next svn diff. That was too long.
So I set up my own SVN. Now I am working with it. As you might have noticed
my current revision is 36. I am not happy with that because it creates more
work for me. But for now I hold to it because it is a tool that helps. I had
published my patchset on Oct 23/24. It was applied to the threading branch
mostly on Nov 13, that is 2/3 of a month later.

Torsten

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe [at] perl
For additional commands, e-mail: dev-help [at] perl


gozer at ectoplasm

Feb 23, 2008, 11:23 PM

Post #7 of 7 (2256 views)
Permalink
Re: $r->location bug [In reply to]

Torsten Foertsch wrote:
> On Fri 22 Feb 2008, Philippe M. Chiasson wrote:
>> - parms.path = path;
>> + parms.path = apr_pstrdup(p, path);
>
> Yes, Philippe, you are right.
>
> In current modperl there are 3 ways to get to modperl_config_insert():
>
> - $r->add_config via modperl_config_insert_request
> - $s->add_config via modperl_config_insert_server
> - $parms->add_config via modperl_config_insert_parms
>
> Since $parms->path is read-only and modperl_config_insert_server passes a NULL
> as path there is only one way to have a custom path passed to
> modperl_config_insert, modperl_config_insert_request. So patching
> $r->add_config only would be sufficient, as well.

Good digging, and correct.

> Nevertheless, fixing it in modperl_config_insert is probably the best way
> regarding future changes.

Yes, it's generally safer to fix it at the source of the problem, as opposed
to hoping folks don't make the same mistake in yet unwritten code.

Committed revision 630597.

--
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
Attachments: signature.asc (0.24 KB)

ModPerl dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.