All,
In coreutils 8.1, src/id.c line 296:
gid_t *groups;
int i;
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
&groups);
if (n_groups < 0 && errno != ENOSYS)
{
if (username)
{
error (0, errno, _("failed to get groups for user
%s"),
quote (username));
}
else
{
error (0, errno, _("failed to get groups for the current
process"));
}
ok = false;
return;
}
if (n_groups > 0)
fputs (_(" groups="), stdout);
for (i = 0; i < n_groups; i++)
{
if (i > 0)
putchar (',');
printf ("%lu", (unsigned long int) groups[i]);
grp = getgrgid (groups[i]);
if (grp)
printf ("(%s)", grp->gr_name);
}
free (groups);
if mgetgroups doesn't find any groups, "groups" will not be changed and
therefore still contain an uninitialised value which is later freed on the
last line of this extract. The fix we have here is to initialise groups to
NULL, then test before we free (although with glibc that isn't actually
necessary).
Thought you might like to know.
Scott.