[Top][All Lists]

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

Re: [PATCH] Use getgrouplist where available.

From: Jim Meyering
Subject: Re: [PATCH] Use getgrouplist where available.
Date: Fri, 22 Feb 2008 10:52:59 +0100

Jim Meyering <address@hidden> wrote:

> "James Youngman" <address@hidden> wrote:
>> On Fri, Feb 22, 2008 at 9:04 AM, Jim Meyering <address@hidden> wrote:
> ...
>>>  +         h = realloc (g, max_n_groups * sizeof *h);
>> Shouldn't realloc here be xnrealloc?
> No.  This function is intended to be usable from a library.
> I.e., no fair calling exit, which xnrealloc does when it fails.
> Also, the function header comment says what happens
> when it fails, and "exit" is not mentioned.

But I suspect your point is that I need to check for overflow.
That's true.  I'm adding this:

diff --git a/gl/lib/mgetgroups.c b/gl/lib/mgetgroups.c
index 317cc7c..ba8818e 100644
--- a/gl/lib/mgetgroups.c
+++ b/gl/lib/mgetgroups.c
@@ -101,8 +101,8 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T 
          /* When getgrouplist fails, it guarantees that
             max_n_groups reflects the new number of groups.  */

-         h = realloc (g, max_n_groups * sizeof *h);
-         if (h == NULL)
+         if (xalloc_oversized (max_n_groups, sizeof *h)
+             || (h = realloc (g, max_n_groups * sizeof *h) == NULL))
              int saved_errno = errno;
              free (g);

reply via email to

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