Skip to content

Commit 78ca1de

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #40079 (php_get_current_user() not thread safe). # Original patch from wharmby at uk dot ibm dot com
1 parent 6a8f688 commit 78ca1de

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44
- Added CURLOPT_TCP_NODELAY constant to Curl extension. (Sara)
55
- Improved proc_open(). Now on Windows it can run external commands not through
66
CMD.EXE. (Dmitry)
7+
- Fixed bug #40079 (php_get_current_user() not thread safe). (Ilia, wharmby
8+
at uk dot ibm dot com)
79
- Fixed bug #40076 (zend_alloc.c: Value of enumeration constant must be in
810
range of signed integer). (Dmitry)
911
- Fixed bug #40073 (exif_read_data dies on certain images). (Tony, Marcus)

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ gettimeofday \
483483
gmtime_r \
484484
getpwnam_r \
485485
getgrnam_r \
486+
getpwuid_r \
486487
grantpt \
487488
inet_ntoa \
488489
inet_ntop \

main/safe_mode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,27 @@ PHPAPI char *php_get_current_user()
228228
return SG(request_info).current_user;
229229
#else
230230
struct passwd *pwd;
231+
#ifdef HAVE_GETPWUID_R
232+
struct passwd _pw;
233+
struct passwd *retpwptr = NULL;
234+
int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
235+
char *pwbuf = emalloc(pwbuflen);
231236

237+
if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
238+
efree(pwbuf);
239+
return "";
240+
}
241+
pwd = &_pw;
242+
#else
232243
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
233244
return "";
234245
}
246+
#endif
235247
SG(request_info).current_user_length = strlen(pwd->pw_name);
236248
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
249+
#ifdef HAVE_GETPWUID_R
250+
efree(pwbuf);
251+
#endif
237252
return SG(request_info).current_user;
238253
#endif
239254
}

0 commit comments

Comments
 (0)