Skip to content

Commit 525d8a8

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fixed bug #79570
2 parents 2f56b00 + 6aff9a5 commit 525d8a8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ PHP NEWS
4848

4949
- Standard:
5050
. Fixed bug #74267 (segfault with streams and invalid data). (cmb)
51+
. Fixed bug #79579 (ZTS build of PHP 7.3.17 doesn't handle ERANGE for
52+
posix_getgrgid and others). (Böszörményi Zoltán)
5153

5254
11 Jun 2020, PHP 7.4.7
5355

ext/posix/posix.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,14 @@ PHP_FUNCTION(posix_getgrgid)
11481148

11491149
grbuf = emalloc(grbuflen);
11501150

1151+
try_again:
11511152
ret = getgrgid_r(gid, &_g, grbuf, grbuflen, &retgrptr);
11521153
if (ret || retgrptr == NULL) {
1154+
if (errno == ERANGE) {
1155+
grbuflen *= 2;
1156+
grbuf = erealloc(grbuf, grbuflen);
1157+
goto try_again;
1158+
}
11531159
POSIX_G(last_error) = ret;
11541160
efree(grbuf);
11551161
RETURN_FALSE;
@@ -1217,7 +1223,13 @@ PHP_FUNCTION(posix_getpwnam)
12171223
buf = emalloc(buflen);
12181224
pw = &pwbuf;
12191225

1226+
try_again:
12201227
if (getpwnam_r(name, pw, buf, buflen, &pw) || pw == NULL) {
1228+
if (errno == ERANGE) {
1229+
buflen *= 2;
1230+
buf = erealloc(buf, buflen);
1231+
goto try_again;
1232+
}
12211233
efree(buf);
12221234
POSIX_G(last_error) = errno;
12231235
RETURN_FALSE;
@@ -1266,8 +1278,14 @@ PHP_FUNCTION(posix_getpwuid)
12661278
}
12671279
pwbuf = emalloc(pwbuflen);
12681280

1281+
try_again:
12691282
ret = getpwuid_r(uid, &_pw, pwbuf, pwbuflen, &retpwptr);
12701283
if (ret || retpwptr == NULL) {
1284+
if (errno == ERANGE) {
1285+
pwbuflen *= 2;
1286+
pwbuf = erealloc(pwbuf, pwbuflen);
1287+
goto try_again;
1288+
}
12711289
POSIX_G(last_error) = ret;
12721290
efree(pwbuf);
12731291
RETURN_FALSE;

0 commit comments

Comments
 (0)