Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions ext/standard/tests/http/gh25693.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php require 'server.inc'; http_server_skipif(); ?>
--FILE--
<?php
require 'server.inc';

class Wrapper {
public $context;

public function stream_open($path, $mode, $options, &$opened_path) {
return true;
}

public function stream_close() {
var_dump(http_get_last_response_headers());
}
}

function request($uri) {
var_dump(file_get_contents($uri));
}

['pid' => $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
Loading