File tree 1 file changed +11
-2
lines changed 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -284,13 +284,21 @@ PHP_FUNCTION(posix_setegid)
284
284
#ifdef HAVE_GETGROUPS
285
285
PHP_FUNCTION (posix_getgroups )
286
286
{
287
- gid_t gidlist [ NGROUPS_MAX ] ;
287
+ gid_t * gidlist ;
288
288
int result ;
289
289
int i ;
290
290
291
291
ZEND_PARSE_PARAMETERS_NONE ();
292
292
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 ) {
294
302
POSIX_G (last_error ) = errno ;
295
303
RETURN_FALSE ;
296
304
}
@@ -300,6 +308,7 @@ PHP_FUNCTION(posix_getgroups)
300
308
for (i = 0 ; i < result ; i ++ ) {
301
309
add_next_index_long (return_value , gidlist [i ]);
302
310
}
311
+ efree (gidlist );
303
312
}
304
313
#endif
305
314
/* }}} */
You can’t perform that action at this time.
0 commit comments