Skip to content

Commit a221e17

Browse files
committed
Fix bug #69625: FPM returns 200 status on request without SCRIPT_FILENAME
1 parent e450621 commit a221e17

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
- Fileinfo:
1919
. Fixed bug #77961 (finfo_open crafted magic parsing SIGABRT). (cmb)
2020

21+
- FPM:
22+
. Fixed bug #69625 (FPM returns 200 status on request without
23+
SCRIPT_FILENAME env). (Jakub Zelenka)
24+
2125
- Intl:
2226
. Fixed bug #80425 (MessageFormatAdapter::getArgTypeList redefined). (Nikita)
2327

sapi/fpm/fpm/fpm_main.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -973,18 +973,16 @@ static void init_request_info(void)
973973

974974
/* initialize the defaults */
975975
SG(request_info).path_translated = NULL;
976-
SG(request_info).request_method = NULL;
976+
SG(request_info).request_method = FCGI_GETENV(request, "REQUEST_METHOD");
977977
SG(request_info).proto_num = 1000;
978978
SG(request_info).query_string = NULL;
979979
SG(request_info).request_uri = NULL;
980980
SG(request_info).content_type = NULL;
981981
SG(request_info).content_length = 0;
982982
SG(sapi_headers).http_response_code = 200;
983983

984-
/* script_path_translated being set is a good indication that
985-
* we are running in a cgi environment, since it is always
986-
* null otherwise. otherwise, the filename
987-
* of the script will be retrieved later via argc/argv */
984+
/* if script_path_translated is not set, then there is no point to carry on
985+
* as the response is 404 and there is no further processing. */
988986
if (script_path_translated) {
989987
const char *auth;
990988
char *content_length = FCGI_GETENV(request, "CONTENT_LENGTH");
@@ -1314,7 +1312,6 @@ static void init_request_info(void)
13141312
SG(request_info).path_translated = estrdup(script_path_translated);
13151313
}
13161314

1317-
SG(request_info).request_method = FCGI_GETENV(request, "REQUEST_METHOD");
13181315
/* FIXME - Work out proto_num here */
13191316
SG(request_info).query_string = FCGI_GETENV(request, "QUERY_STRING");
13201317
SG(request_info).content_type = (content_type ? content_type : "" );
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
FPM: bug69625 - 404 should be returned on missing SCRIPT_FILENAME
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
[unconfined]
14+
listen = {{ADDR}}
15+
pm = dynamic
16+
pm.max_children = 5
17+
pm.start_servers = 1
18+
pm.min_spare_servers = 1
19+
pm.max_spare_servers = 3
20+
EOT;
21+
22+
$code = <<<EOT
23+
<?php
24+
echo "Test\n";
25+
EOT;
26+
27+
$tester = new FPM\Tester($cfg, $code);
28+
$tester->start();
29+
$tester->expectLogStartNotices();
30+
$tester
31+
->request('', ['SCRIPT_FILENAME' => null])
32+
->expectHeader('Status', '404 Not Found')
33+
->expectError('Primary script unknown');
34+
$tester->terminate();
35+
$tester->close();
36+
37+
?>
38+
Done
39+
--EXPECT--
40+
Done
41+
--CLEAN--
42+
<?php
43+
require_once "tester.inc";
44+
FPM\Tester::clean();
45+
?>

sapi/fpm/tests/response.inc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,34 @@ class Response
9898
return $this->expectBody('');
9999
}
100100

101+
/**
102+
* @param string $name
103+
* @param string $value
104+
* @return Response
105+
*/
106+
public function expectHeader($name, $value)
107+
{
108+
$this->checkHeader($name, $value);
109+
110+
return $this;
111+
}
112+
113+
/**
114+
* @param string $errorMessage
115+
* @return Response
116+
*/
117+
public function expectError($errorMessage)
118+
{
119+
$errorData = $this->getErrorData();
120+
if ($errorData !== $errorMessage) {
121+
$this->error(
122+
"The expected error message '$errorMessage' is not equal to returned error '$errorData'"
123+
);
124+
}
125+
126+
return $this;
127+
}
128+
101129
/**
102130
* @param string $contentType
103131
* @return string|null

sapi/fpm/tests/tester.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ class Tester
564564
],
565565
$headers
566566
);
567+
$params = array_filter($params, function($value) {
568+
return !is_null($value);
569+
});
570+
567571
try {
568572
$this->response = new Response(
569573
$this->getClient($address, $connKeepAlive)->request_data($params, false)

0 commit comments

Comments
 (0)