[ALTERNATIVE PATCH] coreutils/id.c: broken logic ?

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 22 03:24:42 UTC 2011


On Tuesday 14 June 2011 02:10, Tito wrote:
> by looking closer at it I now see the bug.

So where is it?

...
> Please take a look at the attached alternative patch that seems to work for me:
> 
> 
> id: fix for the case when the calling process is a member
>     of more than 64 supplementary groups.
> 
> Signed-off-by: Tito Ragusa <farmatito at tiscali.it>
> 
> --- coreutils/id.c.original     2011-06-14 01:18:56.000000000 +0200
> +++ coreutils/id.c      2011-06-14 01:58:06.000000000 +0200
> @@ -110,11 +110,10 @@ static int get_groups(const char *userna
>                 //return m;
>                 //commented out here, happens below anyway
>         } else {
> -               /* On error -1 is returned, which ends up in *n */
> -               int nn = getgroups(*n, groups);
> -               /* 0: nn <= *n, groups[] was big enough; -1 otherwise */
> -               m = - (nn > *n);
> -               *n = nn;
> +               if ((m = getgroups(*n, groups)) < 0 /* && errno == EINVAL */)
> +                       *n = getgroups(0, groups);


Running getgroups twice on a machine where user database is remote
is a bad idea.

-- 
vda


More information about the busybox mailing list