Skip to content

Commit 032905b

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Support more than NGROUPS_MAX groups on macos
2 parents ba6714a + eebcfeb commit 032905b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ext/posix/posix.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,21 @@ PHP_FUNCTION(posix_setegid)
284284
#ifdef HAVE_GETGROUPS
285285
PHP_FUNCTION(posix_getgroups)
286286
{
287-
gid_t gidlist[NGROUPS_MAX];
287+
gid_t *gidlist;
288288
int result;
289289
int i;
290290

291291
ZEND_PARSE_PARAMETERS_NONE();
292292

293-
if ((result = getgroups(NGROUPS_MAX, gidlist)) < 0) {
293+
/* MacOS may return more than NGROUPS_MAX groups.
294+
* Fetch the actual number of groups and create an appropriate allocation. */
295+
if ((result = getgroups(0, NULL)) < 0) {
296+
POSIX_G(last_error) = errno;
297+
RETURN_FALSE;
298+
}
299+
300+
gidlist = emalloc(sizeof(gid_t) * result);
301+
if ((result = getgroups(result, gidlist)) < 0) {
294302
POSIX_G(last_error) = errno;
295303
RETURN_FALSE;
296304
}
@@ -300,6 +308,7 @@ PHP_FUNCTION(posix_getgroups)
300308
for (i=0; i<result; i++) {
301309
add_next_index_long(return_value, gidlist[i]);
302310
}
311+
efree(gidlist);
303312
}
304313
#endif
305314
/* }}} */

0 commit comments

Comments
 (0)