Skip to content

Fix bug #61094: Wrong WSDL cache file name #18709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES
- Core
. PG(arg_separator).input and PG(arg_separator).output are now `zend_string*`
instead of `char*`.
. Added php_get_current_running_user() API to get the (effective) user
running the script.

- Zend
. Added zend_safe_assign_to_variable_noref() function to safely assign
Expand Down
11 changes: 6 additions & 5 deletions ext/soap/php_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3185,22 +3185,23 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl)
unsigned char digest[16];
size_t len = strlen(SOAP_GLOBAL(cache_dir));
time_t cached;
char *user = php_get_current_user();
size_t user_len = user ? strlen(user) + 1 : 0;
size_t user_len = 0;
char *user = php_get_current_running_user(&user_len);

md5str[0] = '\0';
PHP_MD5Init(&md5_context);
PHP_MD5Update(&md5_context, (unsigned char*)uri, uri_len);
PHP_MD5Final(digest, &md5_context);
make_digest(md5str, digest);
key = emalloc(len+sizeof("/wsdl-")-1+user_len+2+sizeof(md5str));
key = emalloc(len+sizeof("/wsdl-")-1+user_len+1+2+sizeof(md5str));
memcpy(key,SOAP_GLOBAL(cache_dir),len);
memcpy(key+len,"/wsdl-",sizeof("/wsdl-")-1);
len += sizeof("/wsdl-")-1;
if (user_len) {
memcpy(key+len, user, user_len-1);
len += user_len-1;
memcpy(key+len, user, user_len);
len += user_len;
key[len++] = '-';
efree(user);
}
if (WSDL_CACHE_VERSION <= 0x9f) {
key[len++] = (WSDL_CACHE_VERSION >> 8) + '0';
Expand Down
114 changes: 72 additions & 42 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,72 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
}
/* }}} */

#ifndef PHP_WIN32
static char *php_translate_uid_to_username(uid_t uid, size_t *len)
{
struct passwd *pwd;
#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;
int err;

if (pwbuflen < 1) {
pwbuflen = 1024;
}
# if ZEND_DEBUG
/* Test retry logic */
pwbuflen = 1;
# endif
pwbuf = emalloc(pwbuflen);

try_again:
err = getpwuid_r(uid, &_pw, pwbuf, pwbuflen, &retpwptr);
if (err != 0) {
if (err == ERANGE) {
pwbuflen *= 2;
pwbuf = erealloc(pwbuf, pwbuflen);
goto try_again;
}
efree(pwbuf);
return NULL;
}
if (retpwptr == NULL) {
efree(pwbuf);
return NULL;
}
pwd = &_pw;
#else
if ((pwd=getpwuid(uid))==NULL) {
return NULL;
}
#endif
*len = strlen(pwd->pw_name);
char *result = estrndup(pwd->pw_name, *len);
#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
efree(pwbuf);
#endif
return result;
}
#endif

PHPAPI char *php_get_current_running_user(size_t *len)
{
#ifdef PHP_WIN32
char *name = php_win32_get_username();
if (!name) {
return NULL;
}
*len = strlen(name);
char *result = estrndup(name, *len);
free(name);
return result;
#else
return php_translate_uid_to_username(geteuid(), len);
#endif
}

/* {{{ php_get_current_user */
PHPAPI char *php_get_current_user(void)
{
Expand Down Expand Up @@ -1524,50 +1590,14 @@ PHPAPI char *php_get_current_user(void)
free(name);
return SG(request_info).current_user;
#else
struct passwd *pwd;
#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;
int err;

if (pwbuflen < 1) {
pwbuflen = 1024;
}
# if ZEND_DEBUG
/* Test retry logic */
pwbuflen = 1;
# endif
pwbuf = emalloc(pwbuflen);

try_again:
err = getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr);
if (err != 0) {
if (err == ERANGE) {
pwbuflen *= 2;
pwbuf = erealloc(pwbuf, pwbuflen);
goto try_again;
}
efree(pwbuf);
return "";
}
if (retpwptr == NULL) {
efree(pwbuf);
return "";
}
pwd = &_pw;
#else
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
size_t len;
char *username = php_translate_uid_to_username(pstat->st_uid, &len);
if (!username) {
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);
#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
efree(pwbuf);
#endif
return SG(request_info).current_user;
SG(request_info).current_user_length = (int) len;
SG(request_info).current_user = username;
return username;
#endif
}
}
Expand Down
1 change: 1 addition & 0 deletions main/php.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ PHPAPI int php_register_internal_extensions(void);
PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
PHPAPI void php_com_initialize(void);
PHPAPI char *php_get_current_user(void);
PHPAPI char *php_get_current_running_user(size_t *len);

PHPAPI const char *php_get_internal_encoding(void);
PHPAPI const char *php_get_input_encoding(void);
Expand Down