Skip to content

Commit 7f4513f

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Support more than NGROUPS_MAX groups on macos
2 parents 3e2e2f1 + 032905b commit 7f4513f

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
@@ -290,13 +290,21 @@ PHP_FUNCTION(posix_setegid)
290290
#ifdef HAVE_GETGROUPS
291291
PHP_FUNCTION(posix_getgroups)
292292
{
293-
gid_t gidlist[NGROUPS_MAX];
293+
gid_t *gidlist;
294294
int result;
295295
int i;
296296

297297
ZEND_PARSE_PARAMETERS_NONE();
298298

299-
if ((result = getgroups(NGROUPS_MAX, gidlist)) < 0) {
299+
/* MacOS may return more than NGROUPS_MAX groups.
300+
* Fetch the actual number of groups and create an appropriate allocation. */
301+
if ((result = getgroups(0, NULL)) < 0) {
302+
POSIX_G(last_error) = errno;
303+
RETURN_FALSE;
304+
}
305+
306+
gidlist = emalloc(sizeof(gid_t) * result);
307+
if ((result = getgroups(result, gidlist)) < 0) {
300308
POSIX_G(last_error) = errno;
301309
RETURN_FALSE;
302310
}
@@ -306,6 +314,7 @@ PHP_FUNCTION(posix_getgroups)
306314
for (i=0; i<result; i++) {
307315
add_next_index_long(return_value, gidlist[i]);
308316
}
317+
efree(gidlist);
309318
}
310319
#endif
311320
/* }}} */

0 commit comments

Comments
 (0)