diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 3c970735a538..eefa30ff624b 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -481,6 +481,7 @@ PHP_RSHUTDOWN_FUNCTION(basic) /* {{{ */ /* Free last http headers */ zval_ptr_dtor(&BG(last_http_headers)); + ZVAL_UNDEF(&BG(last_http_headers)); BG(page_uid) = -1; BG(page_gid) = -1; diff --git a/ext/standard/tests/http/gh25693.phpt b/ext/standard/tests/http/gh25693.phpt new file mode 100644 index 000000000000..33d09db3d862 --- /dev/null +++ b/ext/standard/tests/http/gh25693.phpt @@ -0,0 +1,42 @@ +--TEST-- +GH-25693 (Use-after-free of the last response headers in a stream wrapper closed at shutdown) +--CREDITS-- +xuziqiang98 +--INI-- +allow_url_fopen=1 +--SKIPIF-- + +--FILE-- + $pid, 'uri' => $uri] = http_server([ + "data://text/plain,HTTP/1.0 200 Ok\r\n\r\nBody", +]); + +request($uri); + +http_server_kill($pid); + +stream_wrapper_register('test', Wrapper::class); +$fp = fopen('test://', 'r'); +?> +--EXPECT-- +string(4) "Body" +NULL