libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 1d78defba5cba1f11528098dccb82594a3c24f7e
parent cdd4c1f9cc9686fc57ce9e5894c77fb70b3529c6
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Fri, 13 Jun 2025 23:31:43 +0200

conn_data_send.c: fixed large sending, added some asserts

Diffstat:
Msrc/mhd2/conn_data_send.c | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/mhd2/conn_data_send.c b/src/mhd2/conn_data_send.c @@ -199,15 +199,20 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) if (mhd_REPLY_CNTN_LOC_RESP_BUF == c->rp.cntn_loc) { bool complete_response = true; - size_t send_size = - (size_t) (c->rp.rsp_cntn_read_pos - resp->cntn_size); + const uint_fast64_t send_left = + resp->cntn_size - c->rp.rsp_cntn_read_pos; + size_t send_size = (size_t) send_left; + + mhd_assert (MHD_SIZE_UNKNOWN != resp->cntn_size); + mhd_assert (mhd_HTTP_STAGE_UNCHUNKED_BODY_READY == c->stage); mhd_assert (mhd_RESPONSE_CONTENT_DATA_BUFFER == resp->cntn_dtype); mhd_assert (c->rp.rsp_cntn_read_pos < resp->cntn_size); - if ((c->rp.rsp_cntn_read_pos - resp->cntn_size) != send_size) + if (send_left != send_size) { send_size = (size_t) ~((size_t) 0); complete_response = false; + mhd_assert (send_left >= send_size); } res = mhd_send_data (c, @@ -216,6 +221,8 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) + c->rp.rsp_cntn_read_pos, complete_response, &sent); + mhd_assert ((mhd_SOCKET_ERR_NO_ERROR != res) || + sent <= send_size); } else if (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc) { @@ -228,6 +235,9 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) c->write_buffer + c->write_buffer_send_offset, true, &sent); + mhd_assert ((mhd_SOCKET_ERR_NO_ERROR != res) || \ + sent <= (c->write_buffer_append_offset \ + - c->write_buffer_send_offset)); } else if (mhd_REPLY_CNTN_LOC_IOV == c->rp.cntn_loc) { @@ -285,6 +295,7 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) else { c->rp.rsp_cntn_read_pos += sent; + mhd_assert (resp->cntn_size >= c->rp.rsp_cntn_read_pos); if (c->rp.rsp_cntn_read_pos == resp->cntn_size) c->stage = mhd_HTTP_STAGE_FULL_REPLY_SENT; }