Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sapi/cli/php_http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static const uint8_t normal_url_char[256] = {
1, 1, 1, 1, 1, 1, 1, 0 };


#define PARSING_HEADER(state) (state <= s_headers_almost_done && 0 == (parser->flags & F_TRAILING))
#define PARSING_HEADER(state) (state <= s_headers_almost_done)


enum header_states
Expand Down
38 changes: 38 additions & 0 deletions sapi/cli/tests/gh24115.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--

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.

--- a/sapi/cli/tests/gh24115.phpt
+++ b/sapi/cli/tests/gh24115.phpt
@@ -14,7 +14,7 @@ $head = "POST / HTTP/1.1\r\nHost: $host\r\nTransfer-Encoding: chunked\r\nConnect

 function send(string $request): string {
     $fp = php_cli_server_connect();
-    fwrite($fp, $request);
+    @fwrite($fp, $request);
     $response = stream_get_contents($fp);
     fclose($fp);
     return $response;
@@ -26,7 +26,7 @@ echo "small trailer: ", str_contains($response, "200 OK") ? "200" : "FAIL", "\n"

 // A trailer larger than the header size limit is rejected.
 $response = send($head . "0\r\nX-Fill: " . str_repeat("A", 100 * 1024) . "\r\n\r\n");
-echo "oversized trailer: ", str_contains($response, "200 OK") ? "FAIL" : "rejected", "\n";
+echo "oversized trailer: ", $response === '' ? "rejected" : "FAIL", "\n";

 // The server keeps serving requests afterwards.
 $response = send($head . "0\r\n\r\n");

GH-24115 (CLI server: chunked request trailers are not limited by the header size limit)
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
include "php_cli_server.inc";
php_cli_server_start("echo 'OK';");

$host = PHP_CLI_SERVER_HOSTNAME;
$head = "POST / HTTP/1.1\r\nHost: $host\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n4\r\ndata\r\n";

function send(string $request): string {
$fp = php_cli_server_connect();
fwrite($fp, $request);
$response = stream_get_contents($fp);
fclose($fp);
return $response;
}

// A small trailer is still accepted.
$response = send($head . "0\r\nX-Trailer: small\r\n\r\n");
echo "small trailer: ", str_contains($response, "200 OK") ? "200" : "FAIL", "\n";

// A trailer larger than the header size limit is rejected.
$response = send($head . "0\r\nX-Fill: " . str_repeat("A", 100 * 1024) . "\r\n\r\n");
echo "oversized trailer: ", str_contains($response, "200 OK") ? "FAIL" : "rejected", "\n";

// The server keeps serving requests afterwards.
$response = send($head . "0\r\n\r\n");
echo "after rejection: ", str_contains($response, "200 OK") ? "200" : "FAIL", "\n";
?>
--EXPECT--
small trailer: 200
oversized trailer: rejected
after rejection: 200
Loading