]> granicus.if.org Git - php/commitdiff
Fixed bug #40079 (php_get_current_user() not thread safe).
authorIlia Alshanetsky <iliaa@php.net>
Tue, 9 Jan 2007 23:27:22 +0000 (23:27 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 9 Jan 2007 23:27:22 +0000 (23:27 +0000)
# Original patch from wharmby at uk dot ibm dot com

NEWS
configure.in
main/safe_mode.c

diff --git a/NEWS b/NEWS
index d94e3feeb60df1b9ee7498a134d0e97116359849..e8caab387a8b3007d01fd3685344bc4a75628001 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ PHP                                                                        NEWS
 - Added CURLOPT_TCP_NODELAY constant to Curl extension. (Sara)
 - Improved proc_open(). Now on Windows it can run external commands not through
   CMD.EXE. (Dmitry)
+- Fixed bug #40079 (php_get_current_user() not thread safe). (Ilia, wharmby
+  at uk dot ibm dot com)
 - Fixed bug #40076 (zend_alloc.c: Value of enumeration constant must be in
   range of signed integer). (Dmitry)
 - Fixed bug #40073 (exif_read_data dies on certain images). (Tony, Marcus)
index 58104ec816163e540980a0041da991b1c383b317..c8eefea911fad745cf017ac779af2835f297d07d 100644 (file)
@@ -483,6 +483,7 @@ gettimeofday \
 gmtime_r \
 getpwnam_r \
 getgrnam_r \
+getpwuid_r \
 grantpt \
 inet_ntoa \
 inet_ntop \
index 761afcb1ab68a0d2aea5058aaf18c784729ca188..d87c3f3e3f6b9485303c898f9c3a83fbf4f6451f 100644 (file)
@@ -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
        }