Skip to content

Fix SOAP error handler dropping a custom HTTP status line - #25831

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/soap-error-handler-status-line-PHP-8.4
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/soap-error-handler-status-line-PHP-8.4

Conversation

@lacatoire

Copy link
Copy Markdown
Member

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.

To reproduce

Run under php -S:

<?php
header('HTTP/1.1 404 Custom Reason');
use_soap_error_handler(true);
echo $undefinedVar;
echo "plain";

Before: HTTP/1.1 404 Not Found
After: HTTP/1.1 404 Custom Reason, as with the handler off.

The status line was cleared before calling the previous error handler
and only restored when that handler bailed out, so any non-fatal
diagnostic lost it.
Comment thread ext/soap/soap.c
@@ -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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants