Re: com php-src: Fix for #66048: ext/standard/basic_functions.c main/main.c main/php_globals.h main/php_open_temporary_file.c
main/php_open_temporary_file.h
| From: | Dmitry Stogov | Date: | Tue, 12 May 2015 23:02:17 +0000 |
| Subject: | Re: com php-src: Fix for #66048: ext/standard/basic_functions.c main/main.c main/php_globals.h main/php_open_temporary_file.c main/php_open_temporary_file.h |
||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-86715@lists.php.net to get a copy of this message | ||
Hi Julien,
it looks like this patch is wrong.
The following tests started to fail.
> Bug #54268 (Double free when destroy_zend_class fails)
[Zend/tests/bug54268.phpt]
> Bug #64720 (SegFault on zend_deactivate) [Zend/tests/bug64720.phpt]
> Bug #68652 (segmentation fault in destructor) [Zend/tests/bug68652.phpt]
> Bug #61367: open_basedir bypass in libxml RSHUTDOWN: read test
[ext/libxml/tests/bug61367-read.phpt]
> Bug #61367: open_basedir bypass in libxml RSHUTDOWN: write test
[ext/libxml/tests/bug61367-write.phpt]
> mysql_pconnect() - killing persitent connection
[ext/mysql/tests/mysql_pconn_kill.phpt]
> Persistent connections and mysql.max_persistent
[ext/mysql/tests/mysql_pconn_max_links.phpt]
Thanks. Dmitry.
On Tue, May 12, 2015 at 5:15 PM, JulienPauli <jpauli@php.net> wrote:
> Commit: 6a819bba40661a9a8d7080994cb2f24b73c5d46c
> Author: Julien Pauli <jpauli@php.net> Wed, 29 Apr 2015
> 14:35:35 +0200
> Parents: c6b986b4e79c8b56c591a50e6e181f5f2b217eaf
> Branches: master
>
> Link:
>
> http://git.php.net/?p=php-src.git;a=commitdiff;h=6a819bba40661a9a8d7080994cb2f24b73c5d46c
>
> Log:
> Fix for #66048
>
> Bugs:
> https://bugs.php.net/66048
>
> Changed paths:
> M ext/standard/basic_functions.c
> M main/main.c
> M main/php_globals.h
> M main/php_open_temporary_file.c
> M main/php_open_temporary_file.h
>
>
> Diff:
> diff --git a/ext/standard/basic_functions.c
> b/ext/standard/basic_functions.c
> index b8113fe..5e23fe2 100644
> --- a/ext/standard/basic_functions.c
> +++ b/ext/standard/basic_functions.c
> @@ -4740,11 +4740,11 @@ PHP_FUNCTION(error_clear_last)
> PG(last_error_type) = 0;
> PG(last_error_lineno) = 0;
>
> - free(PG(last_error_message));
> + efree(PG(last_error_message));
> PG(last_error_message) = NULL;
>
> if (PG(last_error_file)) {
> - free(PG(last_error_file));
> + efree(PG(last_error_file));
> PG(last_error_file) = NULL;
> }
> }
> diff --git a/main/main.c b/main/main.c
> index 23d6a2c..37f4d9c 100644
> --- a/main/main.c
> +++ b/main/main.c
> @@ -990,11 +990,11 @@ static void php_error_cb(int type, const char
> *error_filename, const uint error_
> HANDLE_BLOCK_INTERRUPTIONS();
> #endif
> if (PG(last_error_message)) {
> - free(PG(last_error_message));
> + efree(PG(last_error_message));
> PG(last_error_message) = NULL;
> }
> if (PG(last_error_file)) {
> - free(PG(last_error_file));
> + efree(PG(last_error_file));
> PG(last_error_file) = NULL;
> }
> #ifdef ZEND_SIGNALS
> @@ -1004,8 +1004,8 @@ static void php_error_cb(int type, const char
> *error_filename, const uint error_
> error_filename = "Unknown";
> }
> PG(last_error_type) = type;
> - PG(last_error_message) = strdup(buffer);
> - PG(last_error_file) = strdup(error_filename);
> + PG(last_error_message) = estrdup(buffer);
> + PG(last_error_file) = estrdup(error_filename);
> PG(last_error_lineno) = error_lineno;
> }
>
> @@ -1394,6 +1394,25 @@ static zval
> *php_get_configuration_directive_for_zend(zend_string *name)
> }
> /* }}} */
>
> +/* {{{ php_free_request_globals
> + */
> +static void php_free_request_globals(void)
> +{
> + if (PG(last_error_message)) {
> + efree(PG(last_error_message));
> + PG(last_error_message) = NULL;
> + }
> + if (PG(last_error_file)) {
> + efree(PG(last_error_file));
> + PG(last_error_file) = NULL;
> + }
> + if (PG(php_sys_temp_dir)) {
> + efree(PG(php_sys_temp_dir));
> + PG(php_sys_temp_dir) = NULL;
> + }
> +}
> +/* }}} */
> +
> /* {{{ php_message_handler_for_zend
> */
> static void php_message_handler_for_zend(zend_long message, const void
> *data)
> @@ -1792,15 +1811,8 @@ void php_request_shutdown(void *dummy)
> }
> } zend_end_try();
>
> - /* 8. free last error information */
> - if (PG(last_error_message)) {
> - free(PG(last_error_message));
> - PG(last_error_message) = NULL;
> - }
> - if (PG(last_error_file)) {
> - free(PG(last_error_file));
> - PG(last_error_file) = NULL;
> - }
> + /* 8. free request-bound globals */
> + php_free_request_globals();
>
> /* 9. Shutdown scanner/executor/compiler and restore ini entries */
> zend_deactivate();
> @@ -2350,7 +2362,6 @@ void php_module_shutdown(void)
> #endif
>
> php_output_shutdown();
> - php_shutdown_temporary_directory();
>
> module_initialized = 0;
>
> diff --git a/main/php_globals.h b/main/php_globals.h
> index df2b732..315e3b7 100644
> --- a/main/php_globals.h
> +++ b/main/php_globals.h
> @@ -142,6 +142,8 @@ struct _php_core_globals {
> char *last_error_file;
> int last_error_lineno;
>
> + char *php_sys_temp_dir;
> +
> char *disable_functions;
> char *disable_classes;
> zend_bool allow_url_include;
> diff --git a/main/php_open_temporary_file.c
> b/main/php_open_temporary_file.c
> index a88c823..edd27a5 100644
> --- a/main/php_open_temporary_file.c
> +++ b/main/php_open_temporary_file.c
> @@ -171,25 +171,14 @@ static int php_do_open_temporary_file(const char
> *path, const char *pfx, zend_st
> }
> /* }}} */
>
> -/* Cache the chosen temporary directory. */
> -static char* temporary_directory;
> -
> -PHPAPI void php_shutdown_temporary_directory(void)
> -{
> - if (temporary_directory) {
> - free(temporary_directory);
> - temporary_directory = NULL;
> - }
> -}
> -
> /*
> * Determine where to place temporary files.
> */
> PHPAPI const char* php_get_temporary_directory(void)
> {
> /* Did we determine the temporary directory already? */
> - if (temporary_directory) {
> - return temporary_directory;
> + if (PG(php_sys_temp_dir)) {
> + return PG(php_sys_temp_dir);
> }
>
> /* Is there a temporary directory "sys_temp_dir" in .ini defined?
> */
> @@ -198,11 +187,11 @@ PHPAPI const char* php_get_temporary_directory(void)
> if (sys_temp_dir) {
> int len = (int)strlen(sys_temp_dir);
> if (len >= 2 && sys_temp_dir[len - 1] ==
> DEFAULT_SLASH) {
> - temporary_directory =
> zend_strndup(sys_temp_dir, len - 1);
> - return temporary_directory;
> + PG(php_sys_temp_dir) =
> estrndup(sys_temp_dir, len - 1);
> + return PG(php_sys_temp_dir);
> } else if (len >= 1 && sys_temp_dir[len - 1] !=
> DEFAULT_SLASH) {
> - temporary_directory =
> zend_strndup(sys_temp_dir, len);
> - return temporary_directory;
> + PG(php_sys_temp_dir) =
> estrndup(sys_temp_dir, len);
> + return PG(php_sys_temp_dir);
> }
> }
> }
> @@ -232,24 +221,24 @@ PHPAPI const char* php_get_temporary_directory(void)
> int len = strlen(s);
>
> if (s[len - 1] == DEFAULT_SLASH) {
> - temporary_directory = zend_strndup(s, len
> - 1);
> + PG(php_sys_temp_dir) = estrndup(s, len -
> 1);
> } else {
> - temporary_directory = zend_strndup(s, len);
> + PG(php_sys_temp_dir) = estrndup(s, len);
> }
>
> - return temporary_directory;
> + return PG(php_sys_temp_dir);
> }
> }
> #ifdef P_tmpdir
> /* Use the standard default temporary directory. */
> if (P_tmpdir) {
> - temporary_directory = strdup(P_tmpdir);
> - return temporary_directory;
> + PG(php_sys_temp_dir) = estrdup(P_tmpdir);
> + return PG(php_sys_temp_dir);
> }
> #endif
> /* Shouldn't ever(!) end up here ... last ditch default. */
> - temporary_directory = strdup("/tmp");
> - return temporary_directory;
> + PG(php_sys_temp_dir) = estrdup("/tmp");
> + return PG(php_sys_temp_dir);
> #endif
> }
>
> diff --git a/main/php_open_temporary_file.h
> b/main/php_open_temporary_file.h
> index 912f4a8..3d45fbe 100644
> --- a/main/php_open_temporary_file.h
> +++ b/main/php_open_temporary_file.h
> @@ -26,7 +26,6 @@ PHPAPI FILE *php_open_temporary_file(const char *dir,
> const char *pfx, zend_stri
> PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx,
> zend_string **opened_path_p, zend_bool open_basedir_check);
> PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx,
> zend_string **opened_path_p);
> PHPAPI const char *php_get_temporary_directory(void);
> -PHPAPI void php_shutdown_temporary_directory(void);
> END_EXTERN_C()
>
> #endif /* PHP_OPEN_TEMPORARY_FILE_H */
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>