This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Calling strcmp/strncmp/strcasecmp/strncasecmp with NULL parameter
- From: Roland McGrath <roland at redhat dot com>
- To: Steven Keuchel <steven dot keuchel at freenet dot de>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Tue, 17 Aug 2004 14:13:32 -0700
- Subject: Re: Calling strcmp/strncmp/strcasecmp/strncasecmp with NULL parameter
> in the not so unlikely event, that one of the string compare functions is
> called with NULL as one parameter the process will get a SIGSEGV, because
> the functions are dereferencing NULL pointers (i'm referring to the funcs
> found in sysdeps/generic). I doubt this is intended behaviour, IMHO these
> function should not fail, no matter what the input is.
You are mistaken. Most functions that take pointers have undefined
behavior when given a null pointer or any other inappropriate pointer value.
They behave just like the * operator in this regard. Getting a SIGSEGV is
in fact the single most useful thing that could happen here.