summaryrefslogtreecommitdiff
path: root/main/safe_mode.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2007-01-12 01:46:11 +0000
committerIlia Alshanetsky <iliaa@php.net>2007-01-12 01:46:11 +0000
commit2ae036f038f5b55435cdc7efb18d32831aa27f3a (patch)
tree7e1aec2fd8ea7f02dc1e28e331ff30e4baebb227 /main/safe_mode.c
parented30473f7c9e092de1acf41e10a48f63f87dfebd (diff)
downloadphp-git-2ae036f038f5b55435cdc7efb18d32831aa27f3a.tar.gz
Fixed bug #40098 (php_fopen_primary_script() not thread safe).
Adjusted previous fixes for similar issue to handle sysconf() failures
Diffstat (limited to 'main/safe_mode.c')
-rw-r--r--main/safe_mode.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/main/safe_mode.c b/main/safe_mode.c
index d87c3f3e3f..ad17d482ca 100644
--- a/main/safe_mode.c
+++ b/main/safe_mode.c
@@ -228,12 +228,16 @@ PHPAPI char *php_get_current_user()
return SG(request_info).current_user;
#else
struct passwd *pwd;
-#ifdef HAVE_GETPWUID_R
+#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
struct passwd _pw;
struct passwd *retpwptr = NULL;
int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
- char *pwbuf = emalloc(pwbuflen);
+ char *pwbuf;
+ if (pwbuflen < 1) {
+ return ""
+ }
+ pwbuf = emalloc(pwbuflen);
if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
efree(pwbuf);
return "";
@@ -246,7 +250,7 @@ PHPAPI char *php_get_current_user()
#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
+#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
efree(pwbuf);
#endif
return SG(request_info).current_user;