Skip to content
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
1 change: 0 additions & 1 deletion Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ static const func_info_t func_infos[] = {
#if defined(HAVE_NANOSLEEP)
F1("time_nanosleep", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_BOOL),
#endif
F1("get_current_user", MAY_BE_STRING),
FN("get_cfg_var", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),
F1("error_get_last", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_NULL),
F1("highlight_file", MAY_BE_STRING|MAY_BE_BOOL),
Expand Down
11 changes: 5 additions & 6 deletions ext/soap/php_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3179,8 +3179,7 @@ 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;
zend_string *user = php_get_current_user();

/* System architecture identification (see bug #70951) */
static const char ids[] = {SIZEOF_ZEND_LONG, SOAP_BIG_ENDIAN};
Expand All @@ -3191,13 +3190,13 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl)
PHP_MD5Update(&md5_context, ids, sizeof(ids));
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+ZSTR_LEN(user)+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;
if (ZSTR_LEN(user)) {
memcpy(key+len, ZSTR_VAL(user), ZSTR_LEN(user)-1);
len += ZSTR_LEN(user)-1;
key[len++] = '-';
}
if (WSDL_CACHE_VERSION <= 0x9f) {
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ PHP_FUNCTION(get_current_user)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_STRING(php_get_current_user());
RETURN_STR_COPY(php_get_current_user());
}
/* }}} */

Expand Down
1 change: 0 additions & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,6 @@ function time_nanosleep(int $seconds, int $nanoseconds): array|bool {}
function time_sleep_until(float $timestamp): bool {}
#endif

/** @refcount 1 */
function get_current_user(): string {}

/** @return string|array<int|string, string|array>|false */
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/standard/basic_functions_decl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions main/SAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ SAPI_API void sapi_activate_headers_only(void)
SG(read_post_bytes) = 0;
SG(request_info).request_body = NULL;
SG(request_info).current_user = NULL;
SG(request_info).current_user_length = 0;
SG(request_info).no_headers = 0;
SG(request_info).post_entry = NULL;
SG(global_request_time) = 0;
Expand Down Expand Up @@ -413,7 +412,6 @@ SAPI_API void sapi_activate(void)
SG(read_post_bytes) = 0;
SG(request_info).request_body = NULL;
SG(request_info).current_user = NULL;
SG(request_info).current_user_length = 0;
SG(request_info).no_headers = 0;
SG(request_info).post_entry = NULL;
SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
Expand Down Expand Up @@ -499,7 +497,7 @@ SAPI_API void sapi_deactivate_module(void)
efree(SG(request_info).content_type_dup);
}
if (SG(request_info).current_user) {
efree(SG(request_info).current_user);
zend_string_release_ex(SG(request_info).current_user, false);
}
if (sapi_module.deactivate) {
sapi_module.deactivate();
Expand Down
3 changes: 1 addition & 2 deletions main/SAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ typedef struct {
/* this is necessary for the CGI SAPI module */
char *argv0;

char *current_user;
int current_user_length;
zend_string *current_user;

/* this is necessary for CLI module */
int argc;
Expand Down
21 changes: 8 additions & 13 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
/* }}} */

/* {{{ php_get_current_user */
PHPAPI char *php_get_current_user(void)
PHPAPI zend_string *php_get_current_user(void)
{
zend_stat_t *pstat = NULL;

Expand All @@ -1523,19 +1523,15 @@ PHPAPI char *php_get_current_user(void)
pstat = sapi_get_stat();

if (!pstat) {
return "";
return ZSTR_EMPTY_ALLOC();
} else {
#ifdef PHP_WIN32
char *name = php_win32_get_username();
int len;

if (!name) {
return "";
return ZSTR_EMPTY_ALLOC();
}
len = (int)strlen(name);
name[len] = '\0';
SG(request_info).current_user_length = len;
SG(request_info).current_user = estrndup(name, len);
SG(request_info).current_user = zend_string_init(name, strlen(name), false);
free(name);
return SG(request_info).current_user;
#else
Expand Down Expand Up @@ -1565,20 +1561,19 @@ PHPAPI char *php_get_current_user(void)
goto try_again;
}
efree(pwbuf);
return "";
return ZSTR_EMPTY_ALLOC();
}
if (retpwptr == NULL) {
efree(pwbuf);
return "";
return ZSTR_EMPTY_ALLOC();
}
pwd = &_pw;
#else
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
return "";
return ZSTR_EMPTY_ALLOC();
}
#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);
SG(request_info).current_user = zend_string_init(pwd->pw_name, strlen(pwd->pw_name), false);
#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
efree(pwbuf);
#endif
Expand Down
2 changes: 1 addition & 1 deletion main/php.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ PHPAPI extern int (*php_register_internal_extensions_func)(void);
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 zend_string *php_get_current_user(void);

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