Date: Tue, 22 Apr 2008 22:40:21 -0700 From: "Garrett Cooper" <yanefbsd@gmail.com> To: hackers@freebsd.org Subject: strdup(NULL) supposed to create SIGSEGV? Message-ID: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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 <string.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7d6fde3d0804222240j6b42b77yd86d8accb5a959fa>