Confused by segfault with legitimate call to strerror(3) on amd64 / sysctl(3) setting `odd' errno's

Christoph Mallon christoph.mallon at gmx.de
Fri Jan 16 01:38:21 PST 2009


Garrett Cooper schrieb:
> On Fri, Jan 16, 2009 at 12:58 AM, Garrett Cooper <yanefbsd at gmail.com> wrote:
>> On Fri, Jan 16, 2009 at 12:57 AM, Christoph Mallon
>> <christoph.mallon at gmx.de> wrote:
>>> Garrett Cooper schrieb:
>>>> Good point. I modified the source to do that.
>>>> Thanks,
>>>> -Garrett
>>> You should reply to all so the discussion stays on the list.
>> Yeah, that was a goofup on my part. Go-go Gmail web interface!
>> -Garrett
> 
> Hmmm... looks like the strerror issue it could be a serious bug:
> 
> #include <errno.h>
> #include <stdio.h>
> #include <sys/stat.h>
> 
> int
> main()
> {
> 
>         struct stat sb;
> 
>         int o_errno;
> 
>         if (stat("/some/file/that/doesn't/exist", &sb) != 0) {
>                 o_errno = errno;
>                 printf("Errno: %d\n", errno);
>                 err(errno, "%s", strerror(o_errno));

You are still using the wrong errno.
Also err() itself prints the error string using strerror(). There might 
be some interference when the result of one call to strerror() (your 
call) is used after another call to strerror() (err() internally).

I doubt there is a bug in the library, otherwise we would see many 
bugreports of segfaults on AMD64.


More information about the freebsd-hackers mailing list