mirror of
https://github.com/php/php-src.git
synced 2025-01-27 06:03:45 +08:00
fix bugs #32742 (segmentation fault when the stream with a wrapper is not closed),
#32171 (Userspace stream wrapper crashes PHP)
This commit is contained in:
parent
89316046c9
commit
d5bb03b11a
@ -1219,18 +1219,11 @@ PHP_RSHUTDOWN_FUNCTION(basic)
|
||||
}
|
||||
STR_FREE(BG(locale_string));
|
||||
|
||||
if (FG(stream_wrappers)) {
|
||||
zend_hash_destroy(FG(stream_wrappers));
|
||||
efree(FG(stream_wrappers));
|
||||
FG(stream_wrappers) = NULL;
|
||||
}
|
||||
|
||||
if (FG(stream_filters)) {
|
||||
zend_hash_destroy(FG(stream_filters));
|
||||
efree(FG(stream_filters));
|
||||
FG(stream_filters) = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
FG(stream_wrappers) and FG(stream_filters) are destroyed
|
||||
during php_request_shutdown()
|
||||
*/
|
||||
|
||||
PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
|
||||
|
13
main/main.c
13
main/main.c
@ -1159,6 +1159,10 @@ void php_request_shutdown_for_hook(void *dummy)
|
||||
sapi_deactivate(TSRMLS_C);
|
||||
} zend_end_try();
|
||||
|
||||
zend_try {
|
||||
php_shutdown_stream_hashes(TSRMLS_C);
|
||||
} zend_end_try();
|
||||
|
||||
zend_try {
|
||||
shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
|
||||
} zend_end_try();
|
||||
@ -1234,12 +1238,17 @@ void php_request_shutdown(void *dummy)
|
||||
sapi_deactivate(TSRMLS_C);
|
||||
} zend_end_try();
|
||||
|
||||
/* 10. Free Willy (here be crashes) */
|
||||
/* 10. Destroy stream hashes */
|
||||
zend_try {
|
||||
php_shutdown_stream_hashes(TSRMLS_C);
|
||||
} zend_end_try();
|
||||
|
||||
/* 11. Free Willy (here be crashes) */
|
||||
zend_try {
|
||||
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
|
||||
} zend_end_try();
|
||||
|
||||
/* 11. Reset max_execution_time */
|
||||
/* 12. Reset max_execution_time */
|
||||
zend_try {
|
||||
zend_unset_timeout(TSRMLS_C);
|
||||
} zend_end_try();
|
||||
|
@ -502,6 +502,7 @@ END_EXTERN_C()
|
||||
|
||||
int php_init_stream_wrappers(int module_number TSRMLS_DC);
|
||||
int php_shutdown_stream_wrappers(int module_number TSRMLS_DC);
|
||||
void php_shutdown_stream_hashes(TSRMLS_D);
|
||||
PHP_RSHUTDOWN_FUNCTION(streams);
|
||||
|
||||
BEGIN_EXTERN_C()
|
||||
|
@ -1378,6 +1378,21 @@ static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC
|
||||
FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR);
|
||||
}
|
||||
|
||||
void php_shutdown_stream_hashes(TSRMLS_D)
|
||||
{
|
||||
if (FG(stream_wrappers)) {
|
||||
zend_hash_destroy(FG(stream_wrappers));
|
||||
efree(FG(stream_wrappers));
|
||||
FG(stream_wrappers) = NULL;
|
||||
}
|
||||
|
||||
if (FG(stream_filters)) {
|
||||
zend_hash_destroy(FG(stream_filters));
|
||||
efree(FG(stream_filters));
|
||||
FG(stream_filters) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int php_init_stream_wrappers(int module_number TSRMLS_DC)
|
||||
{
|
||||
le_stream = zend_register_list_destructors_ex(stream_resource_regular_dtor, NULL, "stream", module_number);
|
||||
|
Loading…
Reference in New Issue
Block a user