|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75696 posix_getgrnam fails to print details of group
Submitted: 2017-12-16 03:20 UTC Modified: 2018-09-01 12:35 UTC
From: jas at eecs dot yorku dot ca Assigned: cmb (profile)
Status: Closed Package: POSIX related
PHP Version: 7.2.0 OS: CentOS 7.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jas at eecs dot yorku dot ca
New email:
PHP Version: OS:


 [2017-12-16 03:20 UTC] jas at eecs dot yorku dot ca
I think I've discovered an odd bug.  When I use "posix_getgrnam" to print details on a group in /etc/group, I get back nothing.  If I erase one entry from the group above it, then it works!
example silly /etc/group file:

Without removing user "kkkk" from "labtest" group, posix_getgrnam can't return the details for group tech!

Test script:

Expected result:
I expect to see the group details for group "tech".

Actual result:


try-again (last revision 2018-08-21 15:07 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-21 13:02 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-08-21 13:02 UTC]
The empty result is most likely FALSE; verify this by using
var_dump() instead of print_r().

Also provide the return value of posix_get_last_error(), i.e.
run the following script and post it's output:

 [2018-08-21 13:12 UTC] jas at eecs dot yorku dot ca
-Status: Feedback +Status: Assigned
 [2018-08-21 13:12 UTC] jas at eecs dot yorku dot ca
You are correct.  The output of the script is:
string(29) "Numerical result out of range"

but the group "tech" is a valid system group.
 [2018-08-21 14:16 UTC]
34 is ERANGE. Here it means PHP underestimated the amount of space necessary for a buffer to hold all the information for that group - obviously exhausted by that list of members. It could try again with a larger buffer.
 [2018-08-21 14:19 UTC] jas at eecs dot yorku dot ca
Thanks! Just to confirm - it's therefore a bug in PHP since I can't tell it how much buffer to allocate for the call, right?
 [2018-08-21 15:07 UTC]
The following patch has been added/updated:

Patch Name: try-again
Revision:   1534864074
 [2018-08-21 15:08 UTC]
As requinix already said, what apparently happens is that
sysconf(_SC_GETGR_R_SIZE_MAX) returns a size which is insufficient
(which is allowed by the POSIX spec[1]), and so the following
getgrnam_r() fails with ERANGE[2].  posix_getgrnam() could then
try again with an increased (doubled?) buffer size.

Please try the attached patch (try-again).

[1] <>
[2] <>
 [2018-08-24 16:14 UTC]
-Status: Assigned +Status: Verified -Assigned To: cmb +Assigned To:
 [2018-08-24 16:14 UTC]
<> submitted.
 [2018-09-01 12:32 UTC]
Automatic comment on behalf of
Log: Fix #75696: posix_getgrnam fails to print details of group
 [2018-09-01 12:32 UTC]
-Status: Verified +Status: Closed
 [2018-09-01 12:35 UTC]
-Assigned To: +Assigned To: cmb
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 12:01:28 2024 UTC