diff options
author | Joe Watkins <krakjoe@php.net> | 2019-03-29 19:06:59 +0100 |
---|---|---|
committer | Joe Watkins <krakjoe@php.net> | 2019-03-29 19:06:59 +0100 |
commit | abd0e015a8d126a8efee4b3625b500053ae9827d (patch) | |
tree | 8c2c90683002c3f7f30fdeacdb779cf71817d960 | |
parent | 4006e995772fca4ae2821a0259693901dd229c68 (diff) | |
parent | 072eb6dd77b079a6f90ca5b155f9b0add1b5f2d4 (diff) | |
download | php-git-abd0e015a8d126a8efee4b3625b500053ae9827d.tar.gz |
Merge branch 'PHP-7.4'
* PHP-7.4:
tsrm environment lock
-rw-r--r-- | TSRM/TSRM.c | 16 | ||||
-rw-r--r-- | TSRM/TSRM.h | 7 | ||||
-rw-r--r-- | ext/standard/basic_functions.c | 17 | ||||
-rw-r--r-- | ext/standard/info.c | 2 | ||||
-rw-r--r-- | main/php_variables.c | 4 | ||||
-rw-r--r-- | sapi/litespeed/lsapi_main.c | 2 |
6 files changed, 46 insertions, 2 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index 8b87476210..fa8e5f7736 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -52,7 +52,8 @@ static int resource_types_table_size; static size_t tsrm_reserved_pos = 0; static size_t tsrm_reserved_size = 0; -static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */ +static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */ +static MUTEX_T tsrm_env_mutex; /* tsrm environ mutex */ /* New thread handlers */ static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler = NULL; @@ -145,6 +146,8 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu tsrm_reserved_pos = 0; tsrm_reserved_size = 0; + tsrm_env_mutex = tsrm_mutex_alloc(); + return 1; }/*}}}*/ @@ -191,6 +194,8 @@ TSRM_API void tsrm_shutdown(void) } tsrm_mutex_free(tsmm_mutex); tsmm_mutex = NULL; + tsrm_mutex_free(tsrm_env_mutex); + tsrm_env_mutex = NULL; TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Shutdown TSRM")); if (tsrm_error_file!=stderr) { fclose(tsrm_error_file); @@ -212,6 +217,15 @@ TSRM_API void tsrm_shutdown(void) tsrm_reserved_size = 0; }/*}}}*/ +/* {{{ */ +/* environ lock api */ +TSRM_API int tsrm_env_lock() { + return tsrm_mutex_lock(tsrm_env_mutex); +} + +TSRM_API int tsrm_env_unlock() { + return tsrm_mutex_unlock(tsrm_env_mutex); +} /* }}} */ /* enlarge the arrays for the already active threads */ static void tsrm_update_active_threads(void) diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index 22ccf61744..d5d9065530 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -84,6 +84,10 @@ extern "C" { TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename); TSRM_API void tsrm_shutdown(void); +/* environ lock API */ +TSRM_API int tsrm_env_lock(); +TSRM_API int tsrm_env_unlock(); + /* allocates a new thread-safe-resource id */ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor); @@ -175,6 +179,9 @@ TSRM_API const char *tsrm_api_name(void); #else /* non ZTS */ +#define tsrm_env_lock() 0 +#define tsrm_env_unlock() 0 + #define TSRMG_STATIC(id, type, element) #define TSRMLS_CACHE_EXTERN() #define TSRMLS_CACHE_DEFINE() diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ccd14de59b..f7f3523c86 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -3825,7 +3825,9 @@ PHP_RSHUTDOWN_FUNCTION(basic) /* {{{ */ ZVAL_UNDEF(&BG(strtok_zval)); BG(strtok_string) = NULL; #ifdef HAVE_PUTENV + tsrm_env_lock(); zend_hash_destroy(&BG(putenv_ht)); + tsrm_env_unlock(); #endif BG(mt_rand_is_seeded) = 0; @@ -4134,11 +4136,22 @@ PHP_FUNCTION(getenv) } } #else + + tsrm_env_lock(); + /* system method returns a const */ ptr = getenv(str); + if (ptr) { - RETURN_STRING(ptr); + RETVAL_STRING(ptr); } + + tsrm_env_unlock(); + + if (ptr) { + return; + } + #endif RETURN_FALSE; } @@ -4189,6 +4202,7 @@ PHP_FUNCTION(putenv) } #endif + tsrm_env_lock(); zend_hash_str_del(&BG(putenv_ht), pe.key, pe.key_len); /* find previous value */ @@ -4249,6 +4263,7 @@ PHP_FUNCTION(putenv) tzset(); } #endif + tsrm_env_unlock(); #if defined(PHP_WIN32) free(keyw); free(valw); diff --git a/ext/standard/info.c b/ext/standard/info.c index 570c92393c..4600d66d17 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -954,6 +954,7 @@ PHPAPI void php_print_info(int flag) SECTION("Environment"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); + tsrm_env_lock(); for (env=environ; env!=NULL && *env !=NULL; env++) { tmp1 = estrdup(*env); if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */ @@ -965,6 +966,7 @@ PHPAPI void php_print_info(int flag) php_info_print_table_row(2, tmp1, tmp2); efree(tmp1); } + tsrm_env_unlock(); php_info_print_table_end(); } diff --git a/main/php_variables.c b/main/php_variables.c index decf73a80f..f5692ede4b 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -548,6 +548,8 @@ void _php_import_environment_variables(zval *array_ptr) zval val; zend_ulong idx; + tsrm_env_lock(); + for (env = environ; env != NULL && *env != NULL; env++) { p = strchr(*env, '='); if (!p @@ -572,6 +574,8 @@ void _php_import_environment_variables(zval *array_ptr) php_register_variable_quick(*env, name_len, &val, Z_ARRVAL_P(array_ptr)); } } + + tsrm_env_unlock(); } zend_bool php_std_auto_global_callback(char *name, uint32_t name_len) diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index 64e95d5ceb..2d8eb75326 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -244,6 +244,7 @@ static void litespeed_php_import_environment_variables(zval *array_ptr) return; } + tsrm_env_lock(); for (env = environ; env != NULL && *env != NULL; env++) { p = strchr(*env, '='); if (!p) { /* malformed entry? */ @@ -258,6 +259,7 @@ static void litespeed_php_import_environment_variables(zval *array_ptr) t[nlen] = '\0'; add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr); } + tsrm_env_unlock(); if (t != buf && t != NULL) { efree(t); } |