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/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, z
SG(sapi_headers).http_status_line = NULL;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/ext/soap/soap.c b/ext/soap/soap.c
--- a/ext/soap/soap.c
+++ b/ext/soap/soap.c
@@ -1938,7 +1938,11 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, z
                SG(sapi_headers).http_status_line = NULL;
                zend_try {
                        old_error_handler(error_num, error_filename, error_lineno, message);
-                       SG(sapi_headers).http_status_line = _old_http_status_line;
+                       if (!SG(sapi_headers).http_status_line) {
+                               SG(sapi_headers).http_status_line = _old_http_status_line;
+                       } else if (_old_http_status_line) {
+                               efree(_old_http_status_line);
+                       }
                } zend_catch {
                        CG(in_compilation) = _old_in_compilation;
                        EG(current_execute_data) = _old_current_execute_data;

zend_try {
old_error_handler(error_num, error_filename, error_lineno, message);
SG(sapi_headers).http_status_line = _old_http_status_line;
} zend_catch {
CG(in_compilation) = _old_in_compilation;
EG(current_execute_data) = _old_current_execute_data;
Expand Down
36 changes: 36 additions & 0 deletions ext/soap/tests/error_handler_keeps_status_line.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
SOAP error handler keeps a custom HTTP status line on a non-fatal error
--EXTENSIONS--
soap
--SKIPIF--
<?php
if (!file_exists(__DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php

include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";

$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
if (php_ini_loaded_file()) {
// Necessary such that it works from a development directory in which case extension_dir might not be the real extension dir
$args[] = "-c";
$args[] = php_ini_loaded_file();
}
$code = <<<'PHP'
header('HTTP/1.1 404 Custom Reason');
use_soap_error_handler(true);
echo $undefinedVar;
echo "plain";
PHP;

php_cli_server_start($code, null, $args);

$body = file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS, false, stream_context_create(['http' => ['ignore_errors' => true]]));
echo $http_response_header[0], "\n", $body, "\n";
?>
--EXPECT--
HTTP/1.1 404 Custom Reason
plain
Loading