diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-08-31 06:12:42 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-08-31 06:12:42 +0000 |
commit | 62bcc067edffe1a6e711b496cfb8d0000d67ce01 (patch) | |
tree | 51dfdcbd3cc3d8cc096ccfa15f085d95842e142e /configd/src/apps | |
parent | 1a469dac6684ad13257c83110f0c0b0f821a1ca6 (diff) |
only access mac_groups when getgrouplist was successful
Diffstat (limited to 'configd/src/apps')
-rw-r--r-- | configd/src/apps/su/main.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/configd/src/apps/su/main.cpp b/configd/src/apps/su/main.cpp index 92767710fee..f61faf01fee 100644 --- a/configd/src/apps/su/main.cpp +++ b/configd/src/apps/su/main.cpp @@ -34,8 +34,12 @@ int main(int argc, char** argv) int mac_gid = g; int mac_groups[256]; int ggl = getgrouplist(username, mac_gid, mac_groups, &group_arr_sz); - for (int i = 0; i < group_arr_sz; ++i) { - grouplist[i] = (gid_t) mac_groups[i]; + if (ggl < 0) { + group_arr_sz = 0; + } else { + for (int i = 0; i < group_arr_sz; ++i) { + grouplist[i] = (gid_t) mac_groups[i]; + } } #else int ggl = getgrouplist(username, g, grouplist, &group_arr_sz); @@ -49,7 +53,7 @@ int main(int argc, char** argv) return 1; } size_t listsize = 1; - if (ggl >= 0) { + if (ggl >= 0 && group_arr_sz > 0) { listsize = group_arr_sz; } else { grouplist[0] = g; |