Commit 01f88000b1b for php
commit 01f88000b1ba499c9023ed7bec39ad291cf5ae26
Author: lacatoire <la.catoire@gmail.com>
Date: Thu Nov 26 18:01:11 2026 +0100
ext/soap: Fix SOAP error handler dropping a custom HTTP status line
While the SOAP error handler is active, a non-fatal diagnostic drops a
custom HTTP status line set with header(): the line is set to NULL before
the previous error handler is called and only restored in the zend_catch
block, which runs when that handler bails out. The client gets the default
reason phrase and the custom line is leaked. It is now also restored when
the handler returns.
Close GH-25831
diff --git a/NEWS b/NEWS
index 7a163bb0d62..0591ba30a83 100644
--- a/NEWS
+++ b/NEWS
@@ -252,6 +252,8 @@ PHP NEWS
(lazerg)
. Fixed bug GH-25094 (NULL dereference in get_doc_function() with missing
parts). (lazerg)
+ . Fixed SOAP error handler dropping a custom HTTP status line on a non-fatal
+ error. (lacatoire)
- Sockets:
. Fixed bug GH-25530 (socket_last_error() without a socket returns an error
diff --git a/ext/soap/soap.c b/ext/soap/soap.c
index 3bba56782f3..76669d59ecb 100644
--- a/ext/soap/soap.c
+++ b/ext/soap/soap.c
@@ -1938,6 +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);
+ 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;
diff --git a/ext/soap/tests/error_handler_keeps_status_line.phpt b/ext/soap/tests/error_handler_keeps_status_line.phpt
new file mode 100644
index 00000000000..91c7c59c1da
--- /dev/null
+++ b/ext/soap/tests/error_handler_keeps_status_line.phpt
@@ -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