On Thu, 8 Feb 2001, Nick Tonkin wrote:

>
> Hi all,
>
> No response on this so here it is again, any clues appreciated:
>
> I am encountering a weird problem with Apache::URI ... consider, please,
> this test handler:
>
> package WM::Test;
>
> use strict;
>
> sub handler {
>     my $r = shift;
>     my $uri = Apache::URI->parse($r, $r->uri);
>     $uri->hostname($r->get_server_name);
>     $uri->port($r->get_server_port);
>     print $uri->unparse;
> }
>
> 1;
> __END__
>
> As written, this causes a seg fault every time. Commenting out _either_
> the $uri->hostname assignment _or_ the $uri->port assignment solves the
> problem, or even changing the call to one or other of the methods from an
> assignment to a read. But when both methods are assigned new values, seg
> fault.
>
> This code has worked fine for two years or more on my FreeBSD boxes; this
> is on Linux RedHat 7 ... dunno if that makes a difference.

It doesn't make a difference.  Segfaults for me on Slackware-current, too.
However, I would suggest avoinding RH 7.0 and its buggy compiler!

I've debugged the problem, but have no solution:

     my $uri = Apache::URI->parse($r, $r->uri);

This calls ap_parse_uri_components(), which is responsible for setting
the scheme, hostname, user, password, port, path, etc.  But, the scheme is
not getting set, because the request line only contains "/path" or such.

     $uri->hostname($r->get_server_name);
     $uri->port($r->get_server_port);

These work fine.

     print $uri->unparse;

This calls ap_unparse_uri_components().  If there is a hostname but no
scheme, ap_unparse_uri_components() will pass a null argument to
strcasecmp, which will cause an invalid memory access and SIGSEGV.  You
can work around the problem by including $uri->scheme('http'); with the
other accessor methods.  In the long run this is probably a bug in Apache.

If you read src/main/util_uri.c in Apache, you can see why commenting out
one accessor avoids the crash.

Regards,
Jeffrey Baker

Reply via email to