From owner-freebsd-hackers@FreeBSD.ORG Sat Apr 26 06:34:22 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C6F64106564A for ; Sat, 26 Apr 2008 06:34:22 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.157]) by mx1.freebsd.org (Postfix) with ESMTP id 4EC0D8FC22 for ; Sat, 26 Apr 2008 06:34:22 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: by fg-out-1718.google.com with SMTP id 16so4387867fgg.35 for ; Fri, 25 Apr 2008 23:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=4reMHDG1PLfmgQ7Sd1W3X5HwaHdxVeHemgFRUg4IO4U=; b=VwwWM7ER6oGChwmRuiWzH412d1CBnhGM6pE90WAL1A2B91mABcg65RqmpIErF+mUq1uolrJvyKh3Ny8oboE2RNorYW0j6IKZtBcRia1YZ4Xo6tjZNVayD5Gzp5dmfk0Ni265CQh9oysHS9BsSJawidIuQrYQoxldqIwaa7NccJ8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=auuuqx/eZFEwy9cZkimTFYrT7qlsII45mt03NsYIKVIKmZxThAJrN7w5VkX1tSYFg2tMcscufXO3LlourKG/1urcZCnlxlDA5sQnzJyQ0oEA3MPFMYdFOb+fu2kizrXmVN3oLGMym0YPtYjhy/Q6rAxvXkBRvUHppaSLnFOHFK4= Received: by 10.86.60.15 with SMTP id i15mr2718768fga.36.1209191660893; Fri, 25 Apr 2008 23:34:20 -0700 (PDT) Received: by 10.86.26.8 with HTTP; Fri, 25 Apr 2008 23:34:20 -0700 (PDT) Message-ID: <7d6fde3d0804252334l38ecfd55oaaf69e2428dbf520@mail.gmail.com> Date: Fri, 25 Apr 2008 23:34:20 -0700 From: "Garrett Cooper" To: hackers@freebsd.org In-Reply-To: <7d6fde3d0804252333t499daa3bh1f07bcdd795bef44@mail.gmail.com> MIME-Version: 1.0 References: <7d6fde3d0804232334k2bd569d1j76f128c4157ed75a@mail.gmail.com> <20080424082453.03C1B5B57@mail.bitblocks.com> <7d6fde3d0804252333t499daa3bh1f07bcdd795bef44@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: strdup(NULL) supposed to create SIGSEGV? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Apr 2008 06:34:22 -0000 On Thu, Apr 24, 2008 at 1:24 AM, Bakul Shah wrote: > On Wed, 23 Apr 2008 23:34:41 PDT "Garrett Cooper" > 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