Skip to content

Commit a3891d9

Browse files
committed
Fix GH-9981: FPM does not reset fastcgi.error_header
1 parent 29926c3 commit a3891d9

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
. Fixed bug GH-9891 (DateTime modify with unixtimestamp (@) must work like
1414
setTimestamp). (Derick)
1515

16+
- FPM:
17+
. Fixed bug GH-9981 (FPM does not reset fastcgi.error_header).
18+
(Jakub Zelenka)
19+
1620
- LDAP:
1721
. Fixed bug GH-10112 (LDAP\Connection::__construct() refers to ldap_create()).
1822
(cmb)

sapi/fpm/fpm/fpm_main.c

+3
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,9 @@ consult the installation file that came with this distribution, or visit \n\
19111911

19121912
fpm_request_executing();
19131913

1914+
/* Reset exit status from the previous execution */
1915+
EG(exit_status) = 0;
1916+
19141917
php_execute_script(&file_handle);
19151918

19161919
fastcgi_request_done:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
FPM: gh9981 - fastcgi.error_header is not reset
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc"; ?>
6+
--FILE--
7+
<?php
8+
9+
require_once "tester.inc";
10+
11+
$cfg = <<<EOT
12+
[global]
13+
error_log = {{FILE:LOG}}
14+
[unconfined]
15+
listen = {{ADDR}}
16+
pm = static
17+
pm.max_children = 1
18+
catch_workers_output = yes
19+
EOT;
20+
21+
$code = <<<EOT
22+
<?php
23+
if (isset(\$_GET['q'])) {
24+
echo 'ok';
25+
} else {
26+
d();
27+
}
28+
EOT;
29+
30+
$tester = new FPM\Tester($cfg, $code);
31+
$tester->start(iniEntries: [
32+
'fastcgi.error_header' => '"HTTP/1.1 500 PHP Error"',
33+
'output_buffering' => 4096,
34+
]);
35+
$tester->expectLogStartNotices();
36+
$tester->request()->expectStatus('500 PHP Error');
37+
$tester->request('q=1')->expectNoStatus();
38+
$tester->terminate();
39+
$tester->expectLogTerminatingNotices();
40+
$tester->expectNoLogPattern('/Cannot modify header information/');
41+
$tester->close();
42+
43+
?>
44+
Done
45+
--EXPECT--
46+
Done
47+
--CLEAN--
48+
<?php
49+
require_once "tester.inc";
50+
FPM\Tester::clean();
51+
?>

sapi/fpm/tests/response.inc

+30
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,36 @@ class Response
134134
return $this;
135135
}
136136

137+
/**
138+
* Expect response status.
139+
*
140+
* @param string|null $status Expected status.
141+
*
142+
* @return Response
143+
*/
144+
public function expectStatus(string|null $status): Response {
145+
$headers = $this->getHeaders();
146+
if (is_null($status) && !isset($headers['status'])) {
147+
return $this;
148+
}
149+
if (!is_null($status) && !isset($headers['status'])) {
150+
$this->error('Status is expected but not supplied');
151+
} elseif ($status !== $headers['status']) {
152+
$statusMessage = $status === null ? "expected not to be set": "expected to be $status";
153+
$this->error("Status is $statusMessage but the actual value is {$headers['status']}");
154+
}
155+
return $this;
156+
}
157+
158+
/**
159+
* Expect response status not to be set.
160+
*
161+
* @return Response
162+
*/
163+
public function expectNoStatus(): Response {
164+
return $this->expectStatus(null);
165+
}
166+
137167
/**
138168
* Expect no error in the response.
139169
*

0 commit comments

Comments
 (0)