Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Jan 2009 14:05:33 -0800 (PST)
From:      =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= <mbsd@pacbell.net>
To:        Garrett Cooper <yanefbsd@gmail.com>
Cc:        "amd64@freebsd.org" <amd64@freebsd.org>, Hackers freeBSD <freebsd-hackers@freebsd.org>, Christoph Mallon <christoph.mallon@gmx.de>
Subject:   Re: Confused by segfault with legitimate call to strerror(3) on amd64 / sysctl(3) setting `odd' errno's
Message-ID:  <20090117140506.A2568@antec.home>
In-Reply-To: <7d6fde3d0901160119u7ca9606dw55300cd279410ad2@mail.gmail.com>
References:  <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> <49704AEC.3080709@gmx.de> <7d6fde3d0901160056y7c395cb1m4675a3957b85f33d@mail.gmail.com> <49704C13.60505@gmx.de> <7d6fde3d0901160058x785b0af7r741fc779eb537d5@mail.gmail.com> <7d6fde3d0901160119u7ca9606dw55300cd279410ad2@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

Hi Garrett,

On Fri, 16 Jan 2009, Garrett Cooper wrote:

> On Fri, Jan 16, 2009 at 12:58 AM, Garrett Cooper <yanefbsd@gmail.com> wrote:
>> On Fri, Jan 16, 2009 at 12:57 AM, Christoph Mallon
>> <christoph.mallon@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:

Add #include <string.h>.

Without it you don't get the strerror() prototype, so the return value
defaults to an int. Thus the compiler will truncate the pointer value
to junk.  The crash happens when formatting the output.

Compile with -Wall and pay attention to warnings (or use -Werror)
to catch these things.

     $.02,
     /Mikko

>
> #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));
>        }
>
>        return 0;
>
> }
>
> [gcooper@optimus ~]$ ./badfile
> Errno: 2
> badfile: Segmentation fault: 11 (core dumped)
>
>    I rebuilt my kernel and installed it, and I rebuilt world, but
> haven't installed it yet though, so let me reboot the amd64 machine
> and see what happens (may be a mismatched ABI issue)...
> Cheers,
> -Garrett
> _______________________________________________
> freebsd-amd64@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-amd64
> To unsubscribe, send any mail to "freebsd-amd64-unsubscribe@freebsd.org"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090117140506.A2568>