Skip to content

Commit 551f183

Browse files
committed
Fix a major thread safety bug in the output mechanism
@- Fixed a major memory corruption bug in the thread safe version (Zeev)
1 parent 610ebfe commit 551f183

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

ext/standard/output.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,24 @@ static void php_output_init_globals(OLS_D)
6161

6262

6363
/* Start output layer */
64-
PHPAPI void php_output_startup()
64+
PHPAPI void php_output_startup(void)
6565
{
6666
#ifdef ZTS
6767
output_globals_id = ts_allocate_id(sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL);
6868
#else
6969
php_output_init_globals(OLS_C);
7070
#endif
71+
}
7172

72-
{
73-
OLS_FETCH();
7473

75-
OG(php_body_write) = php_ub_body_write;
76-
OG(php_header_write) = sapi_module.ub_write;
77-
OG(nesting_level) = 0;
78-
OG(lock) = 0;
79-
}
74+
PHPAPI void php_output_activate(void)
75+
{
76+
OLS_FETCH();
77+
78+
OG(php_body_write) = php_ub_body_write;
79+
OG(php_header_write) = sapi_module.ub_write;
80+
OG(nesting_level) = 0;
81+
OG(lock) = 0;
8082
}
8183

8284

ext/standard/php_output.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode);
2727

2828
PHPAPI void php_output_startup(void);
29+
PHPAPI void php_output_activate(void);
2930
void php_output_register_constants(void);
3031
PHPAPI int php_body_write(const char *str, uint str_length);
3132
PHPAPI int php_header_write(const char *str, uint str_length);

main/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
613613

614614
PG(during_request_startup) = 1;
615615

616-
php_output_startup();
616+
php_output_activate();
617617

618618
/* initialize global variables */
619619
PG(modules_activated) = 0;
@@ -829,6 +829,7 @@ int php_module_startup(sapi_module_struct *sf)
829829
sapi_module = *sf;
830830

831831
php_output_startup();
832+
php_output_activate();
832833

833834
zuf.error_function = php_error_cb;
834835
zuf.printf_function = php_printf;

main/output.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,24 @@ static void php_output_init_globals(OLS_D)
6161

6262

6363
/* Start output layer */
64-
PHPAPI void php_output_startup()
64+
PHPAPI void php_output_startup(void)
6565
{
6666
#ifdef ZTS
6767
output_globals_id = ts_allocate_id(sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL);
6868
#else
6969
php_output_init_globals(OLS_C);
7070
#endif
71+
}
7172

72-
{
73-
OLS_FETCH();
7473

75-
OG(php_body_write) = php_ub_body_write;
76-
OG(php_header_write) = sapi_module.ub_write;
77-
OG(nesting_level) = 0;
78-
OG(lock) = 0;
79-
}
74+
PHPAPI void php_output_activate(void)
75+
{
76+
OLS_FETCH();
77+
78+
OG(php_body_write) = php_ub_body_write;
79+
OG(php_header_write) = sapi_module.ub_write;
80+
OG(nesting_level) = 0;
81+
OG(lock) = 0;
8082
}
8183

8284

main/php_output.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode);
2727

2828
PHPAPI void php_output_startup(void);
29+
PHPAPI void php_output_activate(void);
2930
void php_output_register_constants(void);
3031
PHPAPI int php_body_write(const char *str, uint str_length);
3132
PHPAPI int php_header_write(const char *str, uint str_length);

sapi/cgi/cgi_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
502502
case '?':
503503
no_headers = 1;
504504
php_output_startup();
505+
php_output_activate();
505506
SG(headers_sent) = 1;
506507
php_cgi_usage(argv[0]);
507508
php_end_ob_buffers(1);
@@ -566,6 +567,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
566567
case '?':
567568
no_headers = 1;
568569
php_output_startup();
570+
php_output_activate();
569571
SG(headers_sent) = 1;
570572
php_cgi_usage(argv[0]);
571573
php_end_ob_buffers(1);
@@ -592,6 +594,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
592594

593595
case 'm': /* list compiled in modules */
594596
php_output_startup();
597+
php_output_activate();
595598
SG(headers_sent) = 1;
596599
php_printf("Running PHP %s\n%s\n", PHP_VERSION , get_zend_version());
597600
php_printf("[PHP Modules]\n");

0 commit comments

Comments
 (0)