File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ sapi_windows_set_ctrl_handler() leak bug
3+ --SKIPIF--
4+ <?php
5+ include "skipif.inc " ;
6+
7+ if (strtoupper (substr (PHP_OS , 0 , 3 )) !== 'WIN ' )
8+ die ("skip this test is for Windows platforms only " );
9+ ?>
10+ --FILE--
11+ <?php
12+
13+ class Test {
14+ public function set () {
15+ sapi_windows_set_ctrl_handler (self ::cb (...));
16+ }
17+ public function cb () {
18+ }
19+ }
20+
21+ $ test = new Test ;
22+ $ test ->set ();
23+
24+ echo "Done \n" ;
25+
26+ ?>
27+ --EXPECT--
28+ Done
Original file line number Diff line number Diff line change @@ -63,5 +63,7 @@ PHP_RSHUTDOWN_FUNCTION(win32_core_globals)
6363{/*{{{*/
6464 closelog ();
6565
66+ php_win32_signal_ctrl_handler_request_shutdown ();
67+
6668 return SUCCESS ;
6769}/*}}}*/
Original file line number Diff line number Diff line change @@ -68,9 +68,28 @@ PHP_WINUTIL_API void php_win32_signal_ctrl_handler_shutdown(void)
6868 zend_interrupt_function = orig_interrupt_function ;
6969 orig_interrupt_function = NULL ;
7070 vm_interrupt_flag = NULL ;
71- ZVAL_UNDEF (& ctrl_handler );
7271}/*}}}*/
7372
73+ PHP_WINUTIL_API void php_win32_signal_ctrl_handler_request_shutdown (void )
74+ {
75+ /* Must be initialized and in main thread */
76+ if (!vm_interrupt_flag ) {
77+ return ;
78+ }
79+ #ifdef ZTS
80+ if (!tsrm_is_main_thread ()) {
81+ return ;
82+ }
83+ #endif
84+
85+ /* The ctrl_handler must be cleared between requests, otherwise we can crash
86+ * due to accessing a previous request's memory. */
87+ if (!Z_ISUNDEF (ctrl_handler )) {
88+ zval_ptr_dtor (& ctrl_handler );
89+ ZVAL_UNDEF (& ctrl_handler );
90+ }
91+ }
92+
7493static BOOL WINAPI php_win32_signal_system_ctrl_handler (DWORD evt )
7594{/*{{{*/
7695 if (CTRL_C_EVENT != evt && CTRL_BREAK_EVENT != evt ) {
@@ -125,7 +144,7 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler)
125144 RETURN_FALSE ;
126145 }
127146
128- zval_ptr_dtor_nogc (& ctrl_handler );
147+ zval_ptr_dtor (& ctrl_handler );
129148 ZVAL_COPY (& ctrl_handler , & fci .function_name );
130149
131150 RETURN_TRUE ;
Original file line number Diff line number Diff line change 1010#define SIGPROF 27 /* profiling time alarm */
1111
1212PHP_WINUTIL_API void php_win32_signal_ctrl_handler_init (void );
13+ PHP_WINUTIL_API void php_win32_signal_ctrl_handler_request_shutdown (void );
1314PHP_WINUTIL_API void php_win32_signal_ctrl_handler_shutdown (void );
1415
1516#endif /* PHP_WIN32_SIGNAL_H */
You can’t perform that action at this time.
0 commit comments