Re: [PATCH] fix util_lookup_group to handle large groups

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

 



I have recently getting errors like:

  udevd[1030]: error resolving group 'audio': Numerical result out of range

(udevadm --version => 141, uname -r => 2.6.26-TI)
(getent group audio | tr , ' ' | wc => 1 120 874)
(An older system (debian based udevadm --version => 125) works fine)

and found following patch to address the ERANGE problem of getgrnam_r.
(code taken from git.kernel.org, HEAD)

This patch probably has a race condition if sysconf returns 0:

	buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
	if (buflen < 0)			<<-- HERE, better use <=
		buflen = 1000;
	buf = NULL;
	gid = 0;
	for (;;) {
		buf = realloc(buf, buflen);
		if (!buf)
			break;
		errno = 0;
		getgrnam_r(group, &grbuf, buf, buflen, &gr);
		if (gr != NULL)
			gid = gr->gr_gid;
		else if (errno == ERANGE) {
			buflen *= 2;	<<-- 0 * 2 = 0
			continue;
		}

BTW, are there any special reasons not to use getgrnam like this:

gid_t util_lookup_group(struct udev *udev, const char *group)
{
	char *endptr;
	struct group *gr;

	if (strcmp(group, "root") == 0)
		return 0;
	gid = strtoul(group, &endptr, 10);
	if (endptr[0] == '\0')
		return gid;
	
	gr=getgrnam(group);
	if (gr != NULL)
		return gr->gr_gid;
	if (errno == 0 || errno == ENOENT || errno == ESRCH)
		err(udev, "specified group '%s' unknown\n", group);
	else
		err(udev, "error resolving group '%s': %m\n", group);
	return 0;
}

this avoids any buffer handling at all.
the same may apply to util_lookup_user().

Regards
Ansgar
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux