Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Apr 2008 23:34:20 -0700
From:      "Garrett Cooper" <yanefbsd@gmail.com>
To:        hackers@freebsd.org
Subject:   strdup(NULL) supposed to create SIGSEGV?
Message-ID:  <7d6fde3d0804252334l38ecfd55oaaf69e2428dbf520@mail.gmail.com>
In-Reply-To: <7d6fde3d0804252333t499daa3bh1f07bcdd795bef44@mail.gmail.com>
References:  <7d6fde3d0804232334k2bd569d1j76f128c4157ed75a@mail.gmail.com> <20080424082453.03C1B5B57@mail.bitblocks.com> <7d6fde3d0804252333t499daa3bh1f07bcdd795bef44@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Apr 24, 2008 at 1:24 AM, Bakul Shah <bakul@bitblocks.com> wrote:

> On Wed, 23 Apr 2008 23:34:41 PDT "Garrett Cooper" <yanefbsd@gmail.com>
>  wrote:
> > I know that dereferencing a NULL pointer yields a segfault because
> address 0
> > can't be accessed.
> >
> > The point is that I didn't realize that something unadvertised causes a
> > SIGSEGV.
>
> I understood that. We all learn this the hard way!  Reading
> that something will cause SIGSEGV doesn't have the same
> impact as actually seeing your program crash!
>
> > If someone noted that strdup(2) used memcpy(2) (at least) and didn't
> check
> > input (at most), I would completely understand.. I'm more than happy to
> > write that up in the revised manpage if that's what it takes, so others
> > unaware of this can avoid this issue..
>
> strdup(NULL) is an example of the more general case of using
> an illegal  value for a function argument. Are you going to
> update all the manpages for functions that segfault when
> given a NULL? I guess what I am trying to say is don't waste
> your time on that -- even if you update all manpages, people
> are still going to trip over this at least once.
>
> cc -Wall can help find such problems. For strdup(NULL)
> you will get something like
>
> x.c:5: warning: null argument where non-null required (argument 1)
>
> So if you want to help others, make them use cc -Wall :-)
>

    When using things such as getopt, which depend on user input, you can't
do that. gcc is good at mapping out graphs, but it's no more proficient of a
guesser than I am. Besides, it doesn't have a fake Jamaican accent :]..
    I agree though to some extent about the manpage thing, even though this
stupid mistake bit me in the ass due to my own ignorance.
    Also, strdup(3) should reference memcpy(3) in the manpage. I'll submit a
patch for that.
    Discussion closed.
-Garrett



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