You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Stas Bekman <st...@stason.org> on 2004/09/08 23:01:33 UTC

[Fwd: [mp2] coredump strerror code on Solaris 8

Arshavir reports segfaults on Solaris 8 all in the apr land:

Here is one:

#0 0xff2a7fec in apr_cpystrn (dst=0xffbeee90 "яПН\001", src=0x0, dst_size=256)
at apr_cpystrn.c:57
57 if (!(*d = *src)) {
(gdb) where
#0 0xff2a7fec in apr_cpystrn (dst=0xffbeee90 "яПН\001", src=0x0, dst_size=256)
at apr_cpystrn.c:57
#1 0xff2c0f18 in stuffbuffer (buf=0xffbeee90 "яПН\001", bufsize=256, s=0x0)
at errorcodes.c:34
#2 0xff2c18e8 in native_strerror (statcode=-4264304,
buf=0x100 <Address 0x100 out of bounds>, bufsize=0) at errorcodes.c:375

Here is another:

(gdb) bt
#0  apr_cpystrn (dst=0xffbef010 "", src=0x0, dst_size=4290703375)
    at apr_cpystrn.c:57
#1  0xff1d4c4c in stuffbuffer (buf=0xffbeef10 "", bufsize=256, s=0x0)
    at errorcodes.c:34
#2  0xfee074f0 in modperl_error_strerror (rc=500) at modperl_error.c:37
#3  0xfe990c90 in XS_APR__Error_strerror (cv=0x1f4) at Error.xs:36

In the second one the trace seems to be optimized away, since 
modperl_error_strerror does not call stuffbuffer, so it's some internal 
function that is broken.

Anybody has an idea of the cause?


*** /usr/local/apache2/bin/httpd -V
Server version: Apache/2.0.50
Server built:   Aug 31 2004 15:02:12
Server's Module Magic Number: 20020903:8
Architecture:   32-bit
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_PROC_PTHREAD_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D HTTPD_ROOT="/usr/local/apache2/"
-D SUEXEC_BIN="/usr/local/apache2//bin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"


*** (apr|apu)-config linking info

-L/usr/local/apache2//lib -lapr-0 -lsendfile -lrt -lm -lsocket -lnsl 
-lresolv  -lpthread -ldl
-L/usr/local/apache2//lib -laprutil-0 -lgdbm -lexpat -liconv


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Arshavir Grigorian <ag...@m-cam.com>.
Stas Bekman wrote:

> Joe Orton wrote:
>
>> On Wed, Sep 08, 2004 at 06:18:49PM -0400, Stas Bekman wrote:
>>
>>> But normally apr_strerror(500, buf, 256) returns "not specified 
>>> error" string or something like that, which is cool. Why does it 
>>> segfault is what I can't understand. Notice that it doesn't happen 
>>> on linux.
>>
>>
>>
>> strerror(500) will return NULL on Solaris which APR does not expect (and
>> the standards seem to say is wrong behaviour too for what that's worth).
>
>
> Excellent, Joe. Will it make into 2.0.51?
>
>> This patch should fix the issue, thanks for the report:
>>
>> Index: errorcodes.c
>> ===================================================================
>> RCS file: /home/cvs/apr/misc/unix/errorcodes.c,v
>> retrieving revision 1.55.2.2
>> diff -u -r1.55.2.2 errorcodes.c
>> --- errorcodes.c    13 Feb 2004 09:33:49 -0000    1.55.2.2
>> +++ errorcodes.c    9 Sep 2004 08:11:32 -0000
>> @@ -372,7 +372,13 @@
>>      sprintf(err, "Native Error #%d", statcode);
>>      return stuffbuffer(buf, bufsize, err);
>>  #else
>> -    return stuffbuffer(buf, bufsize, strerror(statcode));
>> +    const char *err = strerror(statcode);
>> +    if (err) {
>> +        return stuffbuffer(buf, bufsize, err);
>> +    } else {
>> +        return stuffbuffer(buf, bufsize, +                           
>> "APR does not understand this error code");
>> +    }
>>  #endif
>>  }
>>  #endif
>
>
>
thanks for the fix, Joe. it works fine.

Arshavir

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Arshavir Grigorian <ag...@m-cam.com>.
Stas Bekman wrote:

> Joe Orton wrote:
>
>> On Wed, Sep 08, 2004 at 06:18:49PM -0400, Stas Bekman wrote:
>>
>>> But normally apr_strerror(500, buf, 256) returns "not specified 
>>> error" string or something like that, which is cool. Why does it 
>>> segfault is what I can't understand. Notice that it doesn't happen 
>>> on linux.
>>
>>
>>
>> strerror(500) will return NULL on Solaris which APR does not expect (and
>> the standards seem to say is wrong behaviour too for what that's worth).
>
>
> Excellent, Joe. Will it make into 2.0.51?
>
>> This patch should fix the issue, thanks for the report:
>>
>> Index: errorcodes.c
>> ===================================================================
>> RCS file: /home/cvs/apr/misc/unix/errorcodes.c,v
>> retrieving revision 1.55.2.2
>> diff -u -r1.55.2.2 errorcodes.c
>> --- errorcodes.c    13 Feb 2004 09:33:49 -0000    1.55.2.2
>> +++ errorcodes.c    9 Sep 2004 08:11:32 -0000
>> @@ -372,7 +372,13 @@
>>      sprintf(err, "Native Error #%d", statcode);
>>      return stuffbuffer(buf, bufsize, err);
>>  #else
>> -    return stuffbuffer(buf, bufsize, strerror(statcode));
>> +    const char *err = strerror(statcode);
>> +    if (err) {
>> +        return stuffbuffer(buf, bufsize, err);
>> +    } else {
>> +        return stuffbuffer(buf, bufsize, +                           
>> "APR does not understand this error code");
>> +    }
>>  #endif
>>  }
>>  #endif
>
>
>
thanks for the fix, Joe. it works fine.

Arshavir

Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Stas Bekman <st...@stason.org>.
Joe Orton wrote:
> On Wed, Sep 08, 2004 at 06:18:49PM -0400, Stas Bekman wrote:
> 
>>But normally apr_strerror(500, buf, 256) returns "not specified error" 
>>string or something like that, which is cool. Why does it segfault is what 
>>I can't understand. Notice that it doesn't happen on linux.
> 
> 
> strerror(500) will return NULL on Solaris which APR does not expect (and
> the standards seem to say is wrong behaviour too for what that's worth).

Excellent, Joe. Will it make into 2.0.51?

> This patch should fix the issue, thanks for the report:
> 
> Index: errorcodes.c
> ===================================================================
> RCS file: /home/cvs/apr/misc/unix/errorcodes.c,v
> retrieving revision 1.55.2.2
> diff -u -r1.55.2.2 errorcodes.c
> --- errorcodes.c	13 Feb 2004 09:33:49 -0000	1.55.2.2
> +++ errorcodes.c	9 Sep 2004 08:11:32 -0000
> @@ -372,7 +372,13 @@
>      sprintf(err, "Native Error #%d", statcode);
>      return stuffbuffer(buf, bufsize, err);
>  #else
> -    return stuffbuffer(buf, bufsize, strerror(statcode));
> +    const char *err = strerror(statcode);
> +    if (err) {
> +        return stuffbuffer(buf, bufsize, err);
> +    } else {
> +        return stuffbuffer(buf, bufsize, 
> +                           "APR does not understand this error code");
> +    }
>  #endif
>  }
>  #endif


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Stas Bekman <st...@stason.org>.
Joe Orton wrote:
> On Wed, Sep 08, 2004 at 06:18:49PM -0400, Stas Bekman wrote:
> 
>>But normally apr_strerror(500, buf, 256) returns "not specified error" 
>>string or something like that, which is cool. Why does it segfault is what 
>>I can't understand. Notice that it doesn't happen on linux.
> 
> 
> strerror(500) will return NULL on Solaris which APR does not expect (and
> the standards seem to say is wrong behaviour too for what that's worth).

Excellent, Joe. Will it make into 2.0.51?

> This patch should fix the issue, thanks for the report:
> 
> Index: errorcodes.c
> ===================================================================
> RCS file: /home/cvs/apr/misc/unix/errorcodes.c,v
> retrieving revision 1.55.2.2
> diff -u -r1.55.2.2 errorcodes.c
> --- errorcodes.c	13 Feb 2004 09:33:49 -0000	1.55.2.2
> +++ errorcodes.c	9 Sep 2004 08:11:32 -0000
> @@ -372,7 +372,13 @@
>      sprintf(err, "Native Error #%d", statcode);
>      return stuffbuffer(buf, bufsize, err);
>  #else
> -    return stuffbuffer(buf, bufsize, strerror(statcode));
> +    const char *err = strerror(statcode);
> +    if (err) {
> +        return stuffbuffer(buf, bufsize, err);
> +    } else {
> +        return stuffbuffer(buf, bufsize, 
> +                           "APR does not understand this error code");
> +    }
>  #endif
>  }
>  #endif


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Joe Orton <jo...@redhat.com>.
On Wed, Sep 08, 2004 at 06:18:49PM -0400, Stas Bekman wrote:
> But normally apr_strerror(500, buf, 256) returns "not specified error" 
> string or something like that, which is cool. Why does it segfault is what 
> I can't understand. Notice that it doesn't happen on linux.

strerror(500) will return NULL on Solaris which APR does not expect (and
the standards seem to say is wrong behaviour too for what that's worth).

This patch should fix the issue, thanks for the report:

Index: errorcodes.c
===================================================================
RCS file: /home/cvs/apr/misc/unix/errorcodes.c,v
retrieving revision 1.55.2.2
diff -u -r1.55.2.2 errorcodes.c
--- errorcodes.c	13 Feb 2004 09:33:49 -0000	1.55.2.2
+++ errorcodes.c	9 Sep 2004 08:11:32 -0000
@@ -372,7 +372,13 @@
     sprintf(err, "Native Error #%d", statcode);
     return stuffbuffer(buf, bufsize, err);
 #else
-    return stuffbuffer(buf, bufsize, strerror(statcode));
+    const char *err = strerror(statcode);
+    if (err) {
+        return stuffbuffer(buf, bufsize, err);
+    } else {
+        return stuffbuffer(buf, bufsize, 
+                           "APR does not understand this error code");
+    }
 #endif
 }
 #endif


Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Stas Bekman <st...@stason.org>.
Joe Orton wrote:
> On Wed, Sep 08, 2004 at 05:01:33PM -0400, Stas Bekman wrote:
> 
>>Here is another:
>>
>>(gdb) bt
>>#0  apr_cpystrn (dst=0xffbef010 "", src=0x0, dst_size=4290703375)
>>   at apr_cpystrn.c:57
>>#1  0xff1d4c4c in stuffbuffer (buf=0xffbeef10 "", bufsize=256, s=0x0)
>>   at errorcodes.c:34
>>#2  0xfee074f0 in modperl_error_strerror (rc=500) at modperl_error.c:37
>>#3  0xfe990c90 in XS_APR__Error_strerror (cv=0x1f4) at Error.xs:36
>>
>>In the second one the trace seems to be optimized away, since 
>>modperl_error_strerror does not call stuffbuffer, so it's some internal 
>>function that is broken.
> 
> 
> Three cheers for tail call recursion...  I guess mod_perl_error_strerror
> will call apr_strerror(500, buf, 256) in this case?  Bets are 500 is an
> HTTP status code rather than a genuine apr_status_t so you probably
> didn't really want to do that, but it probably shouldn't segfault
> either.

That's right. Unfortunately Apache didn't provide a way to handle errors 
in filters. I suppose it was assumed that filters can't go wrong. So 500 
is how we try to tell the request that there was a problem in the filter.

But normally apr_strerror(500, buf, 256) returns "not specified error" 
string or something like that, which is cool. Why does it segfault is what 
I can't understand. Notice that it doesn't happen on linux.

The segfault is triggered by mp2 test t/filter/in_error.t should you try 
to reproduce it. This test calls perl's die in the filter to emulate a 
filter error and that's when Arshavir was getting the segfault.

Here is the implementation of modperl_error_strerror:

char *modperl_error_strerror(pTHX_ apr_status_t rc)
{
     char *ptr;
     char buf[256];

     if (rc >= APR_OS_START_USERERR &&
         rc < APR_OS_START_USERERR + MP_error_strings_size) {
         /* custom mod_perl errors */
         ptr = (char*)MP_error_strings[(int)(rc - APR_OS_START_USERERR)];
     }
     else {
         /* apache apr errors */
         ptr = apr_strerror(rc, buf, sizeof(buf));
     }

     /* must copy the string and not return a pointer to the local
      * address. Using a single (per interpreter) static buffer.
      */
     return Perl_form(aTHX_ "%s", ptr);
}

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [Fwd: [mp2] coredump strerror code on Solaris 8

Posted by Joe Orton <jo...@redhat.com>.
On Wed, Sep 08, 2004 at 05:01:33PM -0400, Stas Bekman wrote:
> Here is another:
> 
> (gdb) bt
> #0  apr_cpystrn (dst=0xffbef010 "", src=0x0, dst_size=4290703375)
>    at apr_cpystrn.c:57
> #1  0xff1d4c4c in stuffbuffer (buf=0xffbeef10 "", bufsize=256, s=0x0)
>    at errorcodes.c:34
> #2  0xfee074f0 in modperl_error_strerror (rc=500) at modperl_error.c:37
> #3  0xfe990c90 in XS_APR__Error_strerror (cv=0x1f4) at Error.xs:36
> 
> In the second one the trace seems to be optimized away, since 
> modperl_error_strerror does not call stuffbuffer, so it's some internal 
> function that is broken.

Three cheers for tail call recursion...  I guess mod_perl_error_strerror
will call apr_strerror(500, buf, 256) in this case?  Bets are 500 is an
HTTP status code rather than a genuine apr_status_t so you probably
didn't really want to do that, but it probably shouldn't segfault
either.

joe