strdup(NULL) supposed to create SIGSEGV?
Garrett Cooper
yanefbsd at gmail.com
Wed Apr 23 05:40:23 UTC 2008
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 at 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 at optimus ~]$ uname -a
FreeBSD optimus 8.0-CURRENT FreeBSD 8.0-CURRENT #10: Wed Apr 16 19:47:39 PDT
200
8 root at optimus:/usr/obj/usr/src/sys/OPTIMUS i386
Thanks,
-Garrett
More information about the freebsd-hackers
mailing list