Skip to content

Commit 31db39c

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: sapi/cli: Fix built-in server truncating responses after a partial write
2 parents 06f4640 + 1efdcc6 commit 31db39c

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed BcMath\Number results that truncate to zero keeping a negative sign
77
and comparing less than zero. (Ilia Alshanetsky)
88

9+
- CLI:
10+
. Fixed the built-in server truncating an error page and leaking its
11+
unsent part after a partial socket write. (Ilia Alshanetsky)
12+
913
- Core:
1014
. Fixed OSS-Fuzz #536440507 (Immutable class incorrect assertion).
1115
(ndossche)

‎sapi/cli/php_cli_server.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ static void php_cli_server_content_sender_ctor(php_cli_server_content_sender *se
10501050
static int php_cli_server_content_sender_send(php_cli_server_content_sender *sender, php_socket_t fd, size_t *nbytes_sent_total) /* {{{ */
10511051
{
10521052
php_cli_server_chunk *chunk, *next;
1053-
size_t _nbytes_sent_total = 0;
1053+
1054+
*nbytes_sent_total = 0;
10541055

10551056
for (chunk = sender->buffer.first; chunk; chunk = next) {
10561057
#ifdef PHP_WIN32
@@ -1068,7 +1069,6 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
10681069
nbytes_sent = send(fd, chunk->data.heap.p, chunk->data.heap.len, 0);
10691070
#endif
10701071
if (nbytes_sent < 0) {
1071-
*nbytes_sent_total = _nbytes_sent_total;
10721072
return php_socket_errno();
10731073
#ifdef PHP_WIN32
10741074
} else if (nbytes_sent == chunk->data.heap.len) {
@@ -1084,8 +1084,10 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
10841084
} else {
10851085
chunk->data.heap.p += nbytes_sent;
10861086
chunk->data.heap.len -= nbytes_sent;
1087+
*nbytes_sent_total += nbytes_sent;
1088+
return 0;
10871089
}
1088-
_nbytes_sent_total += nbytes_sent;
1090+
*nbytes_sent_total += nbytes_sent;
10891091
break;
10901092

10911093
case PHP_CLI_SERVER_CHUNK_IMMORTAL:
@@ -1095,7 +1097,6 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
10951097
nbytes_sent = send(fd, chunk->data.immortal.p, chunk->data.immortal.len, 0);
10961098
#endif
10971099
if (nbytes_sent < 0) {
1098-
*nbytes_sent_total = _nbytes_sent_total;
10991100
return php_socket_errno();
11001101
#ifdef PHP_WIN32
11011102
} else if (nbytes_sent == chunk->data.immortal.len) {
@@ -1111,12 +1112,13 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen
11111112
} else {
11121113
chunk->data.immortal.p += nbytes_sent;
11131114
chunk->data.immortal.len -= nbytes_sent;
1115+
*nbytes_sent_total += nbytes_sent;
1116+
return 0;
11141117
}
1115-
_nbytes_sent_total += nbytes_sent;
1118+
*nbytes_sent_total += nbytes_sent;
11161119
break;
11171120
}
11181121
}
1119-
*nbytes_sent_total = _nbytes_sent_total;
11201122
return 0;
11211123
} /* }}} */
11221124

0 commit comments

Comments
 (0)