Skip to content

Commit 6aff9a5

Browse files
Böszörményi Zoltánnikic
authored andcommitted
Fixed bug #79570
Use the same logic for getgrgid_r, getpwnam_r and getpwuid_r as for getgrnam_r in #75696 Closes GH-5740.
1 parent 32f377b commit 6aff9a5

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
@@ -32,6 +32,8 @@ PHP NEWS
3232

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

3638
11 Jun 2020, PHP 7.3.19
3739

ext/posix/posix.c

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

11411141
grbuf = emalloc(grbuflen);
11421142

1143+
try_again:
11431144
ret = getgrgid_r(gid, &_g, grbuf, grbuflen, &retgrptr);
11441145
if (ret || retgrptr == NULL) {
1146+
if (errno == ERANGE) {
1147+
grbuflen *= 2;
1148+
grbuf = erealloc(grbuf, grbuflen);
1149+
goto try_again;
1150+
}
11451151
POSIX_G(last_error) = ret;
11461152
efree(grbuf);
11471153
RETURN_FALSE;
@@ -1209,7 +1215,13 @@ PHP_FUNCTION(posix_getpwnam)
12091215
buf = emalloc(buflen);
12101216
pw = &pwbuf;
12111217

1218+
try_again:
12121219
if (getpwnam_r(name, pw, buf, buflen, &pw) || pw == NULL) {
1220+
if (errno == ERANGE) {
1221+
buflen *= 2;
1222+
buf = erealloc(buf, buflen);
1223+
goto try_again;
1224+
}
12131225
efree(buf);
12141226
POSIX_G(last_error) = errno;
12151227
RETURN_FALSE;
@@ -1258,8 +1270,14 @@ PHP_FUNCTION(posix_getpwuid)
12581270
}
12591271
pwbuf = emalloc(pwbuflen);
12601272

1273+
try_again:
12611274
ret = getpwuid_r(uid, &_pw, pwbuf, pwbuflen, &retpwptr);
12621275
if (ret || retpwptr == NULL) {
1276+
if (errno == ERANGE) {
1277+
pwbuflen *= 2;
1278+
pwbuf = erealloc(pwbuf, pwbuflen);
1279+
goto try_again;
1280+
}
12631281
POSIX_G(last_error) = ret;
12641282
efree(pwbuf);
12651283
RETURN_FALSE;

0 commit comments

Comments
 (0)