File tree 5 files changed +55
-2
lines changed
5 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ PHP NEWS
38
38
. Fixed bug GH-17403 (Potential deadlock when putenv fails). (nielsdos)
39
39
. Fixed bug GH-18400 (http_build_query type error is inaccurate). (nielsdos)
40
40
41
+ - Windows:
42
+ . Fix leak+crash with sapi_windows_set_ctrl_handler(). (nielsdos)
43
+
41
44
- Zip:
42
45
. Fixed bug GH-18431 (Registering ZIP progress callback twice doesn't work).
43
46
(nielsdos)
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)
63
63
{/*{{{*/
64
64
closelog ();
65
65
66
+ php_win32_signal_ctrl_handler_request_shutdown ();
67
+
66
68
return SUCCESS ;
67
69
}/*}}}*/
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)
68
68
zend_interrupt_function = orig_interrupt_function ;
69
69
orig_interrupt_function = NULL ;
70
70
vm_interrupt_flag = NULL ;
71
- ZVAL_UNDEF (& ctrl_handler );
72
71
}/*}}}*/
73
72
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
+
74
93
static BOOL WINAPI php_win32_signal_system_ctrl_handler (DWORD evt )
75
94
{/*{{{*/
76
95
if (CTRL_C_EVENT != evt && CTRL_BREAK_EVENT != evt ) {
@@ -125,7 +144,7 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler)
125
144
RETURN_FALSE ;
126
145
}
127
146
128
- zval_ptr_dtor_nogc (& ctrl_handler );
147
+ zval_ptr_dtor (& ctrl_handler );
129
148
ZVAL_COPY (& ctrl_handler , & fci .function_name );
130
149
131
150
RETURN_TRUE ;
Original file line number Diff line number Diff line change 10
10
#define SIGPROF 27 /* profiling time alarm */
11
11
12
12
PHP_WINUTIL_API void php_win32_signal_ctrl_handler_init (void );
13
+ PHP_WINUTIL_API void php_win32_signal_ctrl_handler_request_shutdown (void );
13
14
PHP_WINUTIL_API void php_win32_signal_ctrl_handler_shutdown (void );
14
15
15
16
#endif /* PHP_WIN32_SIGNAL_H */
You can’t perform that action at this time.
0 commit comments