bug-coreutils
[Top][All Lists]
Advanced

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

Re: mgetgroups realloc issues


From: Jim Meyering
Subject: Re: mgetgroups realloc issues
Date: Wed, 15 Apr 2009 19:43:47 +0200

Pádraig Brady wrote:
> In regard to the realloc() introduced to mgetgroups.c,
> I'm not exactly sure but I think the diff below is required
> to handle realloc(,0) on glibc.
> I.E. I think a double free would have been done and an error
> reported if max_n_groups == 0 (which I presume is possible)?

You might be right.  Though I too wonder if there's an implementation
where max_n_groups can ever be set to 0.  AFAICS, with glibc's
implementation, it cannot be set to 0, since that number must include
the gid argument, regardless of how many groups the user is a member of.

Your change looks safe, so you might as well do that.
But if you do make the change, please add an explanatory comment.

Thanks!

> diff --git a/gl/lib/mgetgroups.c b/gl/lib/mgetgroups.c
> index 736dd87..d841044 100644
> --- a/gl/lib/mgetgroups.c
> +++ b/gl/lib/mgetgroups.c
> @@ -91,7 +91,8 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T 
> **groups)
>           if (ng < 0 && last_n_groups == max_n_groups)
>             max_n_groups *= 2;
>
> -         if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
> +         h = realloc_groupbuf (g, max_n_groups);
> +         if (max_n_groups && h == NULL)
>             {
>               int saved_errno = errno;
>               free (g);
>
>
>
>
> Also I think this may be necessary to ensure that we're
> using the glibc flavour of realloc() ?
>
> diff --git a/gl/modules/mgetgroups b/gl/modules/mgetgroups
> index 8bce53a..53c8a8d 100644
> --- a/gl/modules/mgetgroups
> +++ b/gl/modules/mgetgroups
> @@ -9,6 +9,7 @@ m4/mgetgroups.m4
>  Depends-on:
>  getugroups
>  xalloc
> +realloc
>
>  configure.ac:
>  gl_MGETGROUPS




reply via email to

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