com php-src: Fix #75696: posix_getgrnam fails to print details of group: NEWS ext/posix/posix.c ext/p osix/tests/bug75696.phpt
| From: | Christoph Michael Becker | Date: | Sat, 01 Sep 2018 12:25:59 +0000 |
| Subject: | com php-src: Fix #75696: posix_getgrnam fails to print details of group: NEWS ext/posix/posix.c ext/p osix/tests/bug75696.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-102955@lists.php.net to get a copy of this message | ||
Commit: 2677d438502b68a967d46ffadfadc138070ce762
Author: Christoph M. Becker <cmbecker69@gmx.de> Fri, 24 Aug 2018 17:59:44 +0200
Parents: 7fb7869e13999f419787f56340ca4b4dbbb4eef8
Branches: PHP-7.1 PHP-7..2 PHP-7.3 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2677d438502b68a967d46ffadfadc138070ce762
Log:
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.
Bugs:
https://bugs.php.net/75696
Changed paths:
M NEWS
M ext/posix/posix.c
A ext/posix/tests/bug75696.phpt
Diff:
diff --git a/NEWS b/NEWS
index 1471ce8..3ef07a8 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 066139d..27d91f8 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 0000000..e37f807
--- /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===