From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 05:40:23 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 8626C1065676 for ; Wed, 23 Apr 2008 05:40:23 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.156]) by mx1.freebsd.org (Postfix) with ESMTP id 2B6308FC17 for ; Wed, 23 Apr 2008 05:40:22 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: by fg-out-1718.google.com with SMTP id 16so2672147fgg.35 for ; Tue, 22 Apr 2008 22:40: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:mime-version:content-type; bh=eQRloYhOwrrhCTnQ5iS2EyL5yVjlDk8IoP/majk05hw=; b=liN4w2NnD9ElxMbcwn0Bb7jSFlQ6QcO4Ppt+E8Kr/vDISoK8g6z5JGKu1uBhsJKpzUEM0LKAv7eR2/IlOdXC1mZxEuDzKkkJhAqRTcjxLTLLVLsgBPtXIZ06UyXESKtOwUMrjUv0SNq8GPlH4ipo16lDZ738GgdWo5DiXfzx7HI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=qiaveYq+i8V8m01t/jI7FXpkkykPWng5jz6qlfx6CCOY4DWDxhtEDOGcCGCDWSNBm18S+jc215Xl1ifMLkj0M5c+XLlI1zjHsQRY5xq9glgsoXiwPdtSc6rBJ0o4M1YDjv0ayVH3D2J+yBoEMPU2xK4xQ4QGzYKGOaAR+YoVNqA= Received: by 10.86.79.19 with SMTP id c19mr2376477fgb.16.1208929221664; Tue, 22 Apr 2008 22:40:21 -0700 (PDT) Received: by 10.86.26.8 with HTTP; Tue, 22 Apr 2008 22:40:21 -0700 (PDT) Message-ID: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com> Date: Tue, 22 Apr 2008 22:40:21 -0700 From: "Garrett Cooper" To: hackers@freebsd.org MIME-Version: 1.0 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: Wed, 23 Apr 2008 05:40:23 -0000 Hi all, I made an oops in a program, which uncovered "feature" in strdup(2) that I wasn't aware of before. So I was wondering, is strdup(pointer = NULL) supposed to segfault should this just return NULL and set errno? Good news is that Linux does the same thing (yay?), so at least FreeBSD isn't alone.. Sample: [gcooper@optimus ~]$ ss="strdup_segfault"; gcc -o $ss $ss.c; ./$ss; cat $ss.c Segmentation fault: 11 (core dumped) #include int main() { const char *null_src_p = NULL; char *null_dest_p = strdup(null_src_p); return 0; } My sources are a bit old (last sync and userland recompile was mid~March) but I don't think that libc changes all that often. [gcooper@optimus ~]$ uname -a FreeBSD optimus 8.0-CURRENT FreeBSD 8.0-CURRENT #10: Wed Apr 16 19:47:39 PDT 200 8 root@optimus:/usr/obj/usr/src/sys/OPTIMUS i386 Thanks, -Garrett