From 6aff9a50cae40582d2571e7aa6f336d5c6a99547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B6sz=C3=B6rm=C3=A9nyi=20Zolt=C3=A1n?= Date: Fri, 19 Jun 2020 14:31:28 +0200 Subject: Fixed bug #79570 Use the same logic for getgrgid_r, getpwnam_r and getpwuid_r as for getgrnam_r in #75696 Closes GH-5740. --- NEWS | 2 ++ ext/posix/posix.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) 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; -- cgit v1.2.1