Skip to content

Commit ca40258

Browse files
committed
Fix GH-23764: Built-in server leaks fd on HEAD request for static file
php_cli_server_begin_send_static() opens the file, but for HEAD requests never stores the descriptor in client->file_fd, so nothing closes it. Close it right away; Content-Length comes from the stat and the body is never sent, so the descriptor is not needed.
1 parent 9c2acc3 commit ca40258

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- CLI
66
. Fix GH-22567 (Windows ZTS CLI SAPI should refresh its TSRMLS cache during
77
request activation). (matyhtf)
8+
. Fixed bug GH-23764 (Built-in server leaks a file descriptor on every HEAD
9+
request for a static file). (Jakub Skopal)
810

911
- DOM:
1012
. Fixed use-after-free when re-constructing a DOMXPath whose php:function

‎sapi/cli/php_cli_server.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,11 @@ static zend_result php_cli_server_begin_send_static(php_cli_server *server, php_
21852185
client->content_sender_initialized = true;
21862186
if (client->request.request_method != PHP_HTTP_HEAD) {
21872187
client->file_fd = fd;
2188+
} else {
2189+
/* Content-Length comes from the stat and no body is sent, so the fd is
2190+
not needed; it is still opened so HEAD gets the same 404 as GET on
2191+
an unreadable file. */
2192+
close(fd);
21882193
}
21892194

21902195
{

0 commit comments

Comments
 (0)