From 624a83c21a2a23abec77be955ffb020b629f4bd0 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 27 Jun 2025 20:36:47 +0200 Subject: [PATCH] Allow http_response_code() to clear HTTP start-line Fixes GH-18582 Fixes #81451 --- ext/standard/head.c | 6 ++++++ sapi/cli/tests/gh18582.phpt | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 sapi/cli/tests/gh18582.phpt diff --git a/ext/standard/head.c b/ext/standard/head.c index ccef4be16bdfd..ac1e7cd46b103 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -375,6 +375,12 @@ PHP_FUNCTION(http_response_code) } RETURN_FALSE; } + + if (SG(sapi_headers).http_status_line) { + efree(SG(sapi_headers).http_status_line); + SG(sapi_headers).http_status_line = NULL; + } + zend_long old_response_code; old_response_code = SG(sapi_headers).http_response_code; diff --git a/sapi/cli/tests/gh18582.phpt b/sapi/cli/tests/gh18582.phpt new file mode 100644 index 0000000000000..4ad32354bfffd --- /dev/null +++ b/sapi/cli/tests/gh18582.phpt @@ -0,0 +1,38 @@ +--TEST-- +GH-18582: Allow http_response_code() to clear HTTP start-line +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +HTTP/1.1 403 Forbidden +Host: %s +Date: %s +Connection: close +X-Powered-By: %s +Content-type: text/html; charset=UTF-8 + +404 +403