bug-coreutils
[Top][All Lists]
Advanced

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

Problem with id when mgetgroups returns no groups.


From: scott . gnu . 2009
Subject: Problem with id when mgetgroups returns no groups.
Date: Fri, 4 Dec 2009 10:55:49 +0000
User-agent: Mutt/1.5.20 (2009-06-14)

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]