File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -290,13 +290,21 @@ PHP_FUNCTION(posix_setegid)
290
290
#ifdef HAVE_GETGROUPS
291
291
PHP_FUNCTION (posix_getgroups )
292
292
{
293
- gid_t gidlist [ NGROUPS_MAX ] ;
293
+ gid_t * gidlist ;
294
294
int result ;
295
295
int i ;
296
296
297
297
ZEND_PARSE_PARAMETERS_NONE ();
298
298
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 ) {
300
308
POSIX_G (last_error ) = errno ;
301
309
RETURN_FALSE ;
302
310
}
@@ -306,6 +314,7 @@ PHP_FUNCTION(posix_getgroups)
306
314
for (i = 0 ; i < result ; i ++ ) {
307
315
add_next_index_long (return_value , gidlist [i ]);
308
316
}
317
+ efree (gidlist );
309
318
}
310
319
#endif
311
320
/* }}} */
You can’t perform that action at this time.
0 commit comments