Skip to content

Commit 97f9a67

Browse files
committed
Merge branch 'master' of https://git.php.net/repository/php-src
* 'master' of https://git.php.net/repository/php-src: Tinker with the wording of the short_open_tag description. Fix NEWS: these commits were after 5.5.4 was branched and will be in 5.5.5. Handle CLI server request headers case insensitively. 5.4.21 now
2 parents 3ce8b70 + b8beb65 commit 97f9a67

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

php.ini-development

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@
199199
engine = On
200200

201201
; This directive determines whether or not PHP will recognize code between
202-
; <? and ?> tags as PHP source which should be processed as such. For several
203-
; years we recommended that you not use the short tag shortcut and
204-
; instead to use the full <?php and ?> tag combination. With the widespread use
205-
; of XML and use of these tags by other languages, the server can become easily
206-
; confused and end up parsing the wrong code in the wrong context.
207-
; This shortcut is still supported for backwards compatibility, but we
208-
; recommend against its use.
202+
; <? and ?> tags as PHP source which should be processed as such. It is
203+
; generally recommended that <?php and ?> should be used and that this feature
204+
; should be disabled, as enabling it may result in issues when generating XML
205+
; documents, however this remains supported for backward compatibility reasons.
206+
; Note that this directive does not control the <?= shorthand tag, which can be
207+
; used regardless of this directive.
209208
; Default Value: On
210209
; Development Value: Off
211210
; Production Value: Off

php.ini-production

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,12 @@
199199
engine = On
200200

201201
; This directive determines whether or not PHP will recognize code between
202-
; <? and ?> tags as PHP source which should be processed as such. For several
203-
; years we recommended that you not use the short tag shortcut and
204-
; instead to use the full <?php and ?> tag combination. With the widespread use
205-
; of XML and use of these tags by other languages, the server can become easily
206-
; confused and end up parsing the wrong code in the wrong context.
207-
; This shortcut is still supported for backwards compatibility, but we
208-
; recommend against its use.
209-
; Default Value: On
202+
; <? and ?> tags as PHP source which should be processed as such. It is
203+
; generally recommended that <?php and ?> should be used and that this feature
204+
; should be disabled, as enabling it may result in issues when generating XML
205+
; documents, however this remains supported for backward compatibility reasons.
206+
; Note that this directive does not control the <?= shorthand tag, which can be
207+
; used regardless of this directive.
210208
; Default Value: On
211209
; Development Value: Off
212210
; Production Value: Off

sapi/cli/php_cli_server.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
412412
{
413413
{
414414
char **val;
415-
if (SUCCESS == zend_hash_find(&client->request.headers, "Host", sizeof("Host"), (void**)&val)) {
415+
if (SUCCESS == zend_hash_find(&client->request.headers, "host", sizeof("host"), (void**)&val)) {
416416
smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent);
417417
smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent);
418418
smart_str_appends_ex(buffer, *val, persistent);
@@ -568,7 +568,7 @@ static char *sapi_cli_server_read_cookies(TSRMLS_D) /* {{{ */
568568
{
569569
php_cli_server_client *client = SG(server_context);
570570
char **val;
571-
if (FAILURE == zend_hash_find(&client->request.headers, "Cookie", sizeof("Cookie"), (void**)&val)) {
571+
if (FAILURE == zend_hash_find(&client->request.headers, "cookie", sizeof("cookie"), (void**)&val)) {
572572
return NULL;
573573
}
574574
return *val;
@@ -1566,12 +1566,9 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p
15661566
return 1;
15671567
}
15681568
{
1569-
char *header_name = client->current_header_name;
1570-
size_t header_name_len = client->current_header_name_len;
1571-
char c = header_name[header_name_len];
1572-
header_name[header_name_len] = '\0';
1573-
zend_hash_add(&client->request.headers, header_name, header_name_len + 1, &value, sizeof(char *), NULL);
1574-
header_name[header_name_len] = c;
1569+
char *header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len);
1570+
zend_hash_add(&client->request.headers, header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL);
1571+
efree(header_name);
15751572
}
15761573

15771574
if (client->current_header_name_allocated) {
@@ -1729,7 +1726,7 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli
17291726
request_info->post_data = client->request.content;
17301727
request_info->content_length = request_info->post_data_length = client->request.content_len;
17311728
request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL;
1732-
if (SUCCESS == zend_hash_find(&client->request.headers, "Content-Type", sizeof("Content-Type"), (void**)&val)) {
1729+
if (SUCCESS == zend_hash_find(&client->request.headers, "content-type", sizeof("content-type"), (void**)&val)) {
17331730
request_info->content_type = *val;
17341731
}
17351732
} /* }}} */
@@ -1967,7 +1964,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
19671964
static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */
19681965
char **auth;
19691966
php_cli_server_client_populate_request_info(client, &SG(request_info));
1970-
if (SUCCESS == zend_hash_find(&client->request.headers, "Authorization", sizeof("Authorization"), (void**)&auth)) {
1967+
if (SUCCESS == zend_hash_find(&client->request.headers, "authorization", sizeof("authorization"), (void**)&auth)) {
19711968
php_handle_auth_data(*auth TSRMLS_CC);
19721969
}
19731970
SG(sapi_headers).http_response_code = 200;

sapi/cli/tests/bug65633.phpt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
Bug #65633 (built-in server treat some http headers as case-sensitive)
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
include "php_cli_server.inc";
10+
php_cli_server_start(<<<'PHP'
11+
var_dump($_COOKIE, $_SERVER['HTTP_FOO']);
12+
PHP
13+
);
14+
15+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
16+
$port = intval($port)?:80;
17+
18+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
19+
if (!$fp) {
20+
die("connect failed");
21+
}
22+
23+
if(fwrite($fp, <<<HEADER
24+
GET / HTTP/1.1
25+
cookie: foo=bar
26+
foo: bar
27+
28+
29+
HEADER
30+
)) {
31+
while (!feof($fp)) {
32+
echo fgets($fp);
33+
}
34+
}
35+
36+
fclose($fp);
37+
?>
38+
--EXPECTF--
39+
HTTP/1.1 200 OK
40+
Connection: close
41+
X-Powered-By: %s
42+
Content-type: text/html
43+
44+
array(1) {
45+
["foo"]=>
46+
string(3) "bar"
47+
}
48+
string(3) "bar"

0 commit comments

Comments
 (0)