summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-08-24 17:59:44 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-09-01 14:25:59 +0200
commit2677d438502b68a967d46ffadfadc138070ce762 (patch)
treeab9af111fb20419c5fbe95841200b3bd4d2f7d41
parent7fb7869e13999f419787f56340ca4b4dbbb4eef8 (diff)
downloadphp-git-2677d438502b68a967d46ffadfadc138070ce762.tar.gz
Fix #75696: posix_getgrnam fails to print details of group
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.
-rw-r--r--NEWS2
-rw-r--r--ext/posix/posix.c6
-rw-r--r--ext/posix/tests/bug75696.phpt17
3 files changed, 25 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 1471ce868d..3ef07a8179 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
index 066139df29..27d91f8a6c 100644
--- a/ext/posix/posix.c
+++ b/ext/posix/posix.c
@@ -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;
diff --git a/ext/posix/tests/bug75696.phpt b/ext/posix/tests/bug75696.phpt
new file mode 100644
index 0000000000..e37f8077ce
--- /dev/null
+++ b/ext/posix/tests/bug75696.phpt
@@ -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===