summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--ext/posix/posix.c18
2 files changed, 20 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 33fbff3a54..4568036a7b 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,8 @@ PHP NEWS
- Standard:
. Fixed bug #74267 (segfault with streams and invalid data). (cmb)
+ . Fixed bug #79579 (ZTS build of PHP 7.3.17 doesn't handle ERANGE for
+ posix_getgrgid and others). (Böszörményi Zoltán)
11 Jun 2020, PHP 7.3.19
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
index 5a2f352e41..2826eb0e84 100644
--- a/ext/posix/posix.c
+++ b/ext/posix/posix.c
@@ -1140,8 +1140,14 @@ PHP_FUNCTION(posix_getgrgid)
grbuf = emalloc(grbuflen);
+try_again:
ret = getgrgid_r(gid, &_g, grbuf, grbuflen, &retgrptr);
if (ret || retgrptr == NULL) {
+ if (errno == ERANGE) {
+ grbuflen *= 2;
+ grbuf = erealloc(grbuf, grbuflen);
+ goto try_again;
+ }
POSIX_G(last_error) = ret;
efree(grbuf);
RETURN_FALSE;
@@ -1209,7 +1215,13 @@ PHP_FUNCTION(posix_getpwnam)
buf = emalloc(buflen);
pw = &pwbuf;
+try_again:
if (getpwnam_r(name, pw, buf, buflen, &pw) || pw == NULL) {
+ if (errno == ERANGE) {
+ buflen *= 2;
+ buf = erealloc(buf, buflen);
+ goto try_again;
+ }
efree(buf);
POSIX_G(last_error) = errno;
RETURN_FALSE;
@@ -1258,8 +1270,14 @@ PHP_FUNCTION(posix_getpwuid)
}
pwbuf = emalloc(pwbuflen);
+try_again:
ret = getpwuid_r(uid, &_pw, pwbuf, pwbuflen, &retpwptr);
if (ret || retpwptr == NULL) {
+ if (errno == ERANGE) {
+ pwbuflen *= 2;
+ pwbuf = erealloc(pwbuf, pwbuflen);
+ goto try_again;
+ }
POSIX_G(last_error) = ret;
efree(pwbuf);
RETURN_FALSE;