summaryrefslogtreecommitdiff
path: root/main/safe_mode.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2007-01-09 23:27:22 +0000
committerIlia Alshanetsky <iliaa@php.net>2007-01-09 23:27:22 +0000
commit78ca1de763ef2019c70694c9abe11d012eec377e (patch)
treed4e419e764f204ea8f072a53c3ba6312884024eb /main/safe_mode.c
parent6a8f688af222dcd4c64556da96d43904aa82af79 (diff)
downloadphp-git-78ca1de763ef2019c70694c9abe11d012eec377e.tar.gz
Fixed bug #40079 (php_get_current_user() not thread safe).
# Original patch from wharmby at uk dot ibm dot com
Diffstat (limited to 'main/safe_mode.c')
-rw-r--r--main/safe_mode.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/main/safe_mode.c b/main/safe_mode.c
index 761afcb1ab..d87c3f3e3f 100644
--- a/main/safe_mode.c
+++ b/main/safe_mode.c
@@ -228,12 +228,27 @@ PHPAPI char *php_get_current_user()
return SG(request_info).current_user;
#else
struct passwd *pwd;
+#ifdef HAVE_GETPWUID_R
+ struct passwd _pw;
+ struct passwd *retpwptr = NULL;
+ int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *pwbuf = emalloc(pwbuflen);
+ if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
+ efree(pwbuf);
+ return "";
+ }
+ pwd = &_pw;
+#else
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
return "";
}
+#endif
SG(request_info).current_user_length = strlen(pwd->pw_name);
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
+#ifdef HAVE_GETPWUID_R
+ efree(pwbuf);
+#endif
return SG(request_info).current_user;
#endif
}