aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/firejail/util.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c
index 6fc8a663f..5bb5c257b 100644
--- a/src/firejail/util.c
+++ b/src/firejail/util.c
@@ -117,13 +117,19 @@ static int find_group(gid_t group, const gid_t *groups, int ngroups) {
117// "groups". Always returns the current value of new_ngroups. 117// "groups". Always returns the current value of new_ngroups.
118static int copy_group_ifcont(const char *groupname, 118static int copy_group_ifcont(const char *groupname,
119 const gid_t *groups, int ngroups, 119 const gid_t *groups, int ngroups,
120 gid_t *new_groups, int *new_ngroups) { 120 gid_t *new_groups, int *new_ngroups, int new_sz) {
121 if (*new_ngroups >= new_sz) {
122 errno = ERANGE;
123 goto out;
124 }
125
121 gid_t g = get_group_id(groupname); 126 gid_t g = get_group_id(groupname);
122 if (g && find_group(g, groups, ngroups) >= 0) { 127 if (g && find_group(g, groups, ngroups) >= 0) {
123 new_groups[*new_ngroups] = g; 128 new_groups[*new_ngroups] = g;
124 (*new_ngroups)++; 129 (*new_ngroups)++;
125 } 130 }
126 131
132out:
127 return *new_ngroups; 133 return *new_ngroups;
128} 134}
129 135
@@ -151,7 +157,7 @@ static void clean_supplementary_groups(gid_t gid) {
151 int i = 0; 157 int i = 0;
152 while (allowed[i]) { 158 while (allowed[i]) {
153 copy_group_ifcont(allowed[i], groups, ngroups, 159 copy_group_ifcont(allowed[i], groups, ngroups,
154 new_groups, &new_ngroups); 160 new_groups, &new_ngroups, MAX_GROUPS);
155 i++; 161 i++;
156 } 162 }
157 163