Skip to content

Commit

Permalink
Fix #75696: posix_getgrnam fails to print details of group
Browse files Browse the repository at this point in the history
According to the POSIX specification of `getgrnam_r()` the result of
`sysconf(_SC_GETGR_R_SIZE_MAX)` is an initial value suggested for the
size of the buffer, and `ERANGE` signals that insufficient storage was
supplied.  So if we get `ERANGE`, we try again with a buffer twice as
big, and so on, instead of failing.
  • Loading branch information
cmb69 committed Sep 1, 2018
1 parent 7fb7869 commit 2677d43
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2018, PHP 7.1.23

- POSIX:
Fixed bug #75696 (posix_getgrnam fails to print details of group). (cmb)

13 Sep 2018, PHP 7.1.22

Expand Down
6 changes: 6 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,15 @@ PHP_FUNCTION(posix_getgrnam)
RETURN_FALSE;
}
buf = emalloc(buflen);
try_again:
g = &gbuf;

if (getgrnam_r(name, g, buf, buflen, &g) || g == NULL) {
if (errno == ERANGE) {
buflen *= 2;
buf = erealloc(buf, buflen);
goto try_again;
}
POSIX_G(last_error) = errno;
efree(buf);
RETURN_FALSE;
Expand Down
17 changes: 17 additions & 0 deletions ext/posix/tests/bug75696.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Bug #75696 (posix_getgrnam fails to print details of group)
--SKIPIF--
<?php
if (!extension_loaded('posix')) die('skip posix extension not available');
?>
--FILE--
<?php
$gid = posix_getgid();
$name = posix_getgrgid($gid)['name'];
$info = posix_getgrnam($name);
var_dump(is_array($info));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===

0 comments on commit 2677d43

Please sign in to comment.