Skip to content

Commit 9f98a43

Browse files
author
Moriyoshi Koizumi
committed
- Fixed bug #55107 (Null bytes in URL cause insecure behavior (code execution / code disclosure)).
1 parent 7505322 commit 9f98a43

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sapi/cli/php_cli_server.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ static php_cli_server_http_reponse_status_code_pair status_map[] = {
242242
};
243243

244244
static php_cli_server_http_reponse_status_code_pair template_map[] = {
245+
{ 400, "<h1 class=\"h\">%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
245246
{ 404, "<h1 class=\"h\">%s</h1><p>The requested resource %s was not found on this server.</p>" },
246247
{ 500, "<h1 class=\"h\">%s</h1><p>The server is temporality unavaiable.</p>" }
247248
};
@@ -1600,6 +1601,11 @@ static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server
16001601
destroy_request_info(&SG(request_info));
16011602
return FAILURE;
16021603
}
1604+
if (strlen(client->request.path_translated) != client->request.path_translated_len) {
1605+
/* can't handle paths that contain nul bytes */
1606+
destroy_request_info(&SG(request_info));
1607+
return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC);
1608+
}
16031609
{
16041610
zend_file_handle zfd;
16051611
zfd.type = ZEND_HANDLE_FILENAME;
@@ -1625,6 +1631,11 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
16251631
int fd;
16261632
int status = 200;
16271633

1634+
if (client->request.path_translated && strlen(client->request.path_translated) != client->request.path_translated_len) {
1635+
/* can't handle paths that contain nul bytes */
1636+
return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC);
1637+
}
1638+
16281639
fd = client->request.path_translated ? open(client->request.path_translated, O_RDONLY): -1;
16291640
if (fd < 0) {
16301641
char *errstr = get_last_error();

0 commit comments

Comments
 (0)