]> granicus.if.org Git - shadow/commitdiff
* libmisc/find_new_uid.c, libmisc/find_new_gid.c: Add missing
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 2 Jun 2011 18:40:06 +0000 (18:40 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 2 Jun 2011 18:40:06 +0000 (18:40 +0000)
memory allocation check.

ChangeLog
libmisc/find_new_gid.c
libmisc/find_new_uid.c

index b8dbad05b26eb210669808c1fbca3ca98ffff3d1..fac8d359ba233f6fa000b7de9b51a873b51b1d2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2010-06-02  Cal Peake  <cp@absolutedigital.net>
+2011-06-02  Peter Vrabec  <pvrabec@redhat.com>
+
+       * libmisc/find_new_uid.c, libmisc/find_new_gid.c: Add missing
+       memory allocation check.
+
+2011-06-02  Cal Peake  <cp@absolutedigital.net>
 
        * NEWS, libmisc/addgrps.c: Fix allocator loop. Continue to
        getgroups() when getgroups fails (-1) with errno==EINVAL.
index ce534b6233f805927f70b017d24db16e022908cd..668782eb02173be1f48dc2d5261fccd72feb7d63 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <assert.h>
 #include <stdio.h>
+#include <errno.h>
 
 #include "prototypes.h"
 #include "groupio.h"
@@ -75,7 +76,13 @@ int find_new_gid (bool sys_group,
                                        Prog, (unsigned long) gid_min, getdef_ulong ("GID_MIN", 1000UL), (unsigned long) gid_max);
                }
        }
-       used_gids = alloca (sizeof (bool) * (gid_max +1));
+       used_gids = malloc (sizeof (bool) * (gid_max +1));
+       if (NULL == used_gids) {
+               fprintf (stderr,
+                        _("%s: failed to allocate memory: %s\n"),
+                        Prog, strerror (errno));
+               return -1;
+       }
        memset (used_gids, false, sizeof (bool) * (gid_max + 1));
 
        if (   (NULL != preferred_gid)
@@ -189,6 +196,7 @@ int find_new_gid (bool sys_group,
                }
        }
 
+       free (used_gids);
        *gid = group_id;
        return 0;
 }
index 6077eb1e8c1782ff97eb266fd8ab6d10a79874e6..48472cb1349d58543080e37eedfa5cbdd9dc7e32 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <assert.h>
 #include <stdio.h>
+#include <errno.h>
 
 #include "prototypes.h"
 #include "pwio.h"
@@ -75,7 +76,13 @@ int find_new_uid (bool sys_user,
                                        Prog, (unsigned long) uid_min, getdef_ulong ("UID_MIN", 1000UL), (unsigned long) uid_max);
                }
        }
-       used_uids = alloca (sizeof (bool) * (uid_max +1));
+       used_uids = malloc (sizeof (bool) * (uid_max +1));
+       if (NULL == used_uids) {
+               fprintf (stderr,
+                        _("%s: failed to allocate memory. %s\n"),
+                        Prog, strerror (errno));
+               return -1;
+       }
        memset (used_uids, false, sizeof (bool) * (uid_max + 1));
 
        if (   (NULL != preferred_uid)
@@ -189,6 +196,7 @@ int find_new_uid (bool sys_user,
                }
        }
 
+       free (used_uids);
        *uid = user_id;
        return 0;
 }