aboutsummaryrefslogtreecommitdiffstats
path: root/libselinux/src/seusers.c
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2012-11-29 09:41:38 -0500
committerEric Paris <eparis@redhat.com>2013-02-05 20:14:45 -0500
commitaa62cd60f7192123b509c2518e7a2083e34a65a2 (patch)
treeb2dfbf0d25bacffdd62248b38db322be98c213af /libselinux/src/seusers.c
parentafe88d8c69543b2ebd6e25efdaab76f40ea4d3c7 (diff)
downloadandroid_external_selinux-aa62cd60f7192123b509c2518e7a2083e34a65a2.tar.gz
android_external_selinux-aa62cd60f7192123b509c2518e7a2083e34a65a2.tar.bz2
android_external_selinux-aa62cd60f7192123b509c2518e7a2083e34a65a2.zip
libselinux: Fix errors found by coverity
Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libselinux/src/seusers.c')
-rw-r--r--libselinux/src/seusers.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/libselinux/src/seusers.c b/libselinux/src/seusers.c
index cfea186a..09e704be 100644
--- a/libselinux/src/seusers.c
+++ b/libselinux/src/seusers.c
@@ -141,9 +141,16 @@ static int check_group(const char *group, const char *name, const gid_t gid) {
}
if (getgrouplist(name, gid, NULL, &ng) < 0) {
- groups = (gid_t *) malloc(sizeof (gid_t) * ng);
- if (!groups) goto done;
- if (getgrouplist(name, gid, groups, &ng) < 0) goto done;
+ if (ng == 0)
+ goto done;
+ groups = calloc(ng, sizeof(*groups));
+ if (!groups)
+ goto done;
+ if (getgrouplist(name, gid, groups, &ng) < 0)
+ goto done;
+ } else {
+ /* WTF? ng was 0 and we didn't fail? Are we in 0 groups? */
+ goto done;
}
for (i = 0; i < ng; i++) {