php.net |  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
 [2017-12-16 03:20 UTC] jas at eecs dot yorku dot ca
Description:
------------
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:
root:x:0:
labtest:*:31003:a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii,jjj,kkk,lll,mmm,nnn,ooo,ppp,qqq,rrr,sss,ttt,uuu,vvv,www,xxx,yyy,zzz,aaaa,bbbb,cccc,dddd,eeee,ffff,gggg,hhhh,iiii,jjjj,kkkk
tech:*:1000:tdb

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


Test script:
---------------
<?php
print_r(posix_getgrnam("tech"));
?>

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

Actual result:
--------------
empty.

Patches

try-again (last revision 2018-08-21 15:07 UTC by cmb@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-21 13:02 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-08-21 13:02 UTC] cmb@php.net
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:

    <?php
    var_dump(posix_getgrnam("tech"));
    var_dump(posix_get_last_error());
    var_dump(posix_strerror(posix_get_last_error()));
    ?>
 [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:
 
bool(false)
int(34)
string(29) "Numerical result out of range"

but the group "tech" is a valid system group.
 [2018-08-21 14:16 UTC] requinix@php.net
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] cmb@php.net
The following patch has been added/updated:

Patch Name: try-again
Revision:   1534864074
URL:        https://bugs.php.net/patch-display.php?bug=75696&patch=try-again&revision=1534864074
 [2018-08-21 15:08 UTC] cmb@php.net
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] <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getgrnam.html>
[2] <https://github.com/php/php-src/blob/php-7.3.0beta2/ext/posix/posix.c#L1079-L1090>
 [2018-08-24 16:14 UTC] cmb@php.net
-Status: Assigned +Status: Verified -Assigned To: cmb +Assigned To:
 [2018-08-24 16:14 UTC] cmb@php.net
<https://github.com/php/php-src/pull/3464> submitted.
 [2018-09-01 12:32 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2677d438502b68a967d46ffadfadc138070ce762
Log: Fix #75696: posix_getgrnam fails to print details of group
 [2018-09-01 12:32 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-09-01 12:35 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 13:01:27 2024 UTC