libmicrohttpd2

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

commit 25407df59136a540933a386b17ac451248a3ff97
parent a7234c57290f1a179da3c1dc7717102341a69db3
Author: Evgeny Grin <k2k@drgrin.dev>
Date:   Sat,  3 May 2025 21:49:03 +0300

Fixes for 32-bit platforms

Diffstat:
Msrc/mhd2/conn_data_send.c | 27+++++++++++++++++++++++----
Msrc/mhd2/response_from.c | 4++++
Msrc/mhd2/stream_process_request.c | 7++++---
3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/mhd2/conn_data_send.c b/src/mhd2/conn_data_send.c @@ -120,17 +120,26 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) { /* Send response headers alongside the response body, if the body * data is available. */ + bool complete_response = true; + size_t body_size = (size_t) resp->cntn_size; mhd_assert (mhd_RESPONSE_CONTENT_DATA_BUFFER == resp->cntn_dtype); mhd_assert (! c->rp.props.chunked); + mhd_assert (MHD_SIZE_UNKNOWN != resp->cntn_size); + + if (resp->cntn_size != body_size) + { + body_size = (size_t) ~((size_t) 0); + complete_response = false; + } res = mhd_send_hdr_and_body (c, wb_ready, c->write_buffer + c->write_buffer_send_offset, false, - resp->cntn_size, + body_size, (const char *) resp->cntn.buf, - true, + complete_response, &sent); } else @@ -160,6 +169,7 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) mhd_assert (0 == c->rp.rsp_cntn_read_pos); mhd_assert (! c->rp.props.chunked); mhd_assert (c->rp.props.send_reply_body); + mhd_assert (MHD_SIZE_UNKNOWN != resp->cntn_size); c->stage = mhd_HTTP_STAGE_UNCHUNKED_BODY_READY; c->write_buffer_send_offset += wb_ready; c->rp.rsp_cntn_read_pos = sent - wb_ready; @@ -187,14 +197,23 @@ mhd_conn_data_send (struct MHD_Connection *restrict c) (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc)); 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); 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) + { + send_size = (size_t) ~((size_t) 0); + complete_response = false; + } + res = mhd_send_data (c, - c->rp.rsp_cntn_read_pos - resp->cntn_size, + send_size, (const char *) resp->cntn.buf + c->rp.rsp_cntn_read_pos, - true, + complete_response, &sent); } else if (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc) diff --git a/src/mhd2/response_from.c b/src/mhd2/response_from.c @@ -145,8 +145,10 @@ MHD_response_from_buffer ( { struct MHD_Response *restrict res; +#if SIZEOF_SIZE_T >= 8 if (MHD_SIZE_UNKNOWN == buffer_size) return NULL; +#endif /* SIZEOF_SIZE_T >= 8 */ res = response_create_basic (sc, buffer_size, free_cb, free_cb_cls); if (NULL != res) @@ -177,8 +179,10 @@ MHD_response_from_buffer_copy ( const unsigned char *buf_copy; unsigned char *new_buf; +#if SIZEOF_SIZE_T >= 8 if (MHD_SIZE_UNKNOWN == buffer_size) return NULL; +#endif /* SIZEOF_SIZE_T >= 8 */ if (0 != buffer_size) { diff --git a/src/mhd2/stream_process_request.c b/src/mhd2/stream_process_request.c @@ -2901,7 +2901,8 @@ check_and_alloc_buf_for_upload_processing (struct MHD_Connection *restrict c) if ((c->rq.cntn.cntn_size > c->rq.app_act.head_act.data.upload.large_buffer_size) || - ! mhd_daemon_get_lbuf (c->daemon, c->rq.cntn.cntn_size, + ! mhd_daemon_get_lbuf (c->daemon, + (size_t) c->rq.cntn.cntn_size, &(c->rq.cntn.lbuf))) { if (NULL != c->rq.app_act.head_act.data.upload.inc.cb) @@ -3359,7 +3360,7 @@ process_request_chunked_body (struct MHD_Connection *restrict c) act = c->rq.app_act.head_act.data.upload.inc.cb ( c->rq.app_act.head_act.data.upload.inc.cls, &(c->rq), - c->rq.cntn.recv_size, + (size_t) c->rq.cntn.recv_size, c->rq.cntn.lbuf.data); c->rq.cntn.proc_size = c->rq.cntn.recv_size; mhd_daemon_free_lbuf (d, &(c->rq.cntn.lbuf)); @@ -3549,7 +3550,7 @@ mhd_stream_call_app_final_upload_cb (struct MHD_Connection *restrict c) act = c->rq.app_act.head_act.data.upload.full.cb ( c->rq.app_act.head_act.data.upload.full.cls, &(c->rq), - c->rq.cntn.recv_size, + (size_t) c->rq.cntn.recv_size, c->rq.cntn.lbuf.data); c->rq.cntn.proc_size = c->rq.cntn.recv_size; }