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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ PHP NEWS
. Fixed bug GH-23301 (Nested "yield from" yields a value twice when the
middle generator delegates again). (Lazizbek Ergashev)

- CLI:
. Fixed bug GH-23425 (sapi_cli_server_send_headers() does not check the
return value of php_cli_server_client_send_through()). (Lazizbek Ergashev)

- DOM:
. Fixed a use-after-free when cloning a DOMNameSpaceNode after
DOMDocument::xinclude(). (iliaal)
Expand Down
9 changes: 5 additions & 4 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,11 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers) /* {{
}
smart_str_appendl(&buffer, "\r\n", 2);

php_cli_server_client_send_through(client, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s));
size_t buffer_len = ZSTR_LEN(buffer.s);
bool sent = php_cli_server_client_send_through(client, ZSTR_VAL(buffer.s), buffer_len) == buffer_len;

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.

note that php_cli_server_client_send_through returns the number of bytes left on failure so it s wrong here if nothing was consumed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. On failure the callee returned nbytes_left, which equals str_len when nothing was sent, same value as success. Fixed in e2f8bcd: it now returns bytes actually sent (str_len - nbytes_left) on both paths, so this comparison is unambiguous.


smart_str_free(&buffer);
return SAPI_HEADER_SENT_SUCCESSFULLY;
return sent ? SAPI_HEADER_SENT_SUCCESSFULLY : SAPI_HEADER_SEND_FAILED;
}
/* }}} */

Expand Down Expand Up @@ -1920,11 +1921,11 @@ static size_t php_cli_server_client_send_through(php_cli_server_client *client,
} else {
/* error or timeout */
php_handle_aborted_connection();
return nbytes_left;
return str_len - nbytes_left;
}
} else {
php_handle_aborted_connection();
return nbytes_left;
return str_len - nbytes_left;
}
}
nbytes_left -= nbytes_sent;
Expand Down
Loading