[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#296490: libc6: getgrnam segfault (using __nscd_getgrnam_r)



On Tue, Feb 22, 2005 at 09:50:55PM +0100, Tom Parker wrote:
> Florian Weimer wrote:
> >* Tom Parker:
> >>Calling getgrnam() with a NULL argument, with group in
> >>/etc/nsswitch.conf set to 'compat' can cause a segfault in
> >>__nscd_getgrnam_r due to a lack of a check for a NULL string before
> >>doing strlen().
> >
> >Is there any standard that defines the behavior of getgrnam(NULL)?
> 
> The man page GETGRNAM(3) says:
> 
> RETURN VALUE
>        The getgrnam() and getgrgid() functions return a pointer to the 
> group information structure, or NULL if the matching entry is not found 
> or an error occurs. If an error occurs, errno is set appropriately. If 
> one wants to check errno after the call, it should be set to zero before 
> the call.
> 
> I've had a quick look at the POSIX (1003.1-2004) specs, and they say 
> approximately the same thing (see 
> http://www.opengroup.org/onlinepubs/000095399/functions/getgrnam.html). 
> There isn't an exact thing for what to do in the case of getgrnam(NULL), 
> but given that the "matching entry is not found" (because there can't be 
> a NULL group), then I think that returning NULL is the correct behaviour.

No, it's not at all the same thing.  None of the library functions are
required to be robust against NULL input; there's no point making an
exception for getgrnam without making an exception for, say, strlen.

-- 
Daniel Jacobowitz
CodeSourcery, LLC



Reply to: