diff options
author | Eric Paris <eparis@redhat.com> | 2012-11-29 09:41:38 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2013-02-05 20:14:45 -0500 |
commit | aa62cd60f7192123b509c2518e7a2083e34a65a2 (patch) | |
tree | b2dfbf0d25bacffdd62248b38db322be98c213af /libselinux/src/seusers.c | |
parent | afe88d8c69543b2ebd6e25efdaab76f40ea4d3c7 (diff) | |
download | android_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.c | 13 |
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++) { |