From ec57eb2b2e62fba653d3434f1e9284fbfa7bacde Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Mon, 7 Apr 2025 20:07:22 +0300 Subject: [PATCH] Fixed connection initialisation on platforms with non-zero NULL pointers --- src/mhd2/daemon_add_conn.c | 42 ++++++++++++++++++++++++++++++++------ src/mhd2/stream_funcs.c | 21 ++++++++++++++++++- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/mhd2/daemon_add_conn.c b/src/mhd2/daemon_add_conn.c index 15a9986e..81db2d11 100644 --- a/src/mhd2/daemon_add_conn.c +++ b/src/mhd2/daemon_add_conn.c @@ -81,6 +81,11 @@ /** * Set initial internal states for the connection to start reading and * processing incoming data. + * This sets: + * + data processing stage + * + stream request and reply initial data + * + connection read and write buffers + * * @param c the connection to process */ static void @@ -93,14 +98,28 @@ connection_set_initial_state (struct MHD_Connection *restrict c) c->conn_reuse = mhd_CONN_KEEPALIVE_POSSIBLE; c->event_loop_info = MHD_EVENT_LOOP_INFO_RECV; - memset (&c->rq, 0, sizeof(c->rq)); - memset (&c->rp, 0, sizeof(c->rp)); + // TODO: move request reset to special function + memset (&(c->rq), 0, sizeof(c->rq)); + // TODO: move reply reset to special function + memset (&(c->rp), 0, sizeof(c->rp)); #ifndef HAVE_NULL_PTR_ALL_ZEROS - mhd_DLINKEDL_INIT_LINKS (c, all_conn); - mhd_DLINKEDL_INIT_LINKS (c, proc_ready); - mhd_DLINKEDL_INIT_LINKS (c, by_timeout); - // TODO: set all other pointers manually + // TODO: move request reset to special function + mhd_DLINKEDL_INIT_LIST (&(c->rq), fields); +#ifdef MHD_SUPPORT_POST_PARSER + mhd_DLINKEDL_INIT_LIST (&(c->rq), post_fields); +#endif /* MHD_SUPPORT_POST_PARSER */ + c->rq.version = NULL; + c->rq.url = NULL; + c->rq.field_lines.start = NULL; + c->rq.app_context = NULL; + c->rq.hdrs.rq_line.rq_tgt = NULL; + c->rq.hdrs.rq_line.rq_tgt_qmark = NULL; + + // TODO: move reply reset to special function + c->rp.app_act_ctx.connection = NULL; + c->rp.response = NULL; + c->rp.resp_iov.iov = NULL; #endif /* ! HAVE_NULL_PTR_ALL_ZEROS */ c->write_buffer = NULL; @@ -188,6 +207,17 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, } else { +#ifndef HAVE_NULL_PTR_ALL_ZEROS + mhd_DLINKEDL_INIT_LINKS (c, all_conn); + c->extr_event.app_cntx = NULL; + mhd_DLINKEDL_INIT_LINKS (c, proc_ready); + mhd_DLINKEDL_INIT_LINKS (c, by_timeout); +# ifdef MHD_SUPPORT_UPGRADE + c->upgr.c = NULL; + mhd_DLINKEDL_INIT_LINKS (c, upgr_cleanup); +# endif /* MHD_SUPPORT_UPGRADE */ + c->socket_context = NULL; +#endif /* ! HAVE_NULL_PTR_ALL_ZEROS */ #ifdef MHD_SUPPORT_HTTPS if (0 != tls_data_size) c->tls = (struct mhd_TlsConnData *) (c + 1); diff --git a/src/mhd2/stream_funcs.c b/src/mhd2/stream_funcs.c index 59346a2e..3c9c0884 100644 --- a/src/mhd2/stream_funcs.c +++ b/src/mhd2/stream_funcs.c @@ -571,12 +571,31 @@ mhd_stream_finish_req_serving (struct MHD_Connection *restrict c, (0 == c->read_buffer_offset) ? MHD_EVENT_LOOP_INFO_RECV : MHD_EVENT_LOOP_INFO_PROCESS; + // TODO: move request reset to special function memset (&c->rq, 0, sizeof(c->rq)); + // TODO: move reply reset to special function /* iov (if any) will be deallocated by mhd_pool_reset */ memset (&c->rp, 0, sizeof(c->rp)); - // TODO: set all rq and tp pointers to NULL manually. Do the same in other places. +#ifndef HAVE_NULL_PTR_ALL_ZEROS + // TODO: move request reset to special function + mhd_DLINKEDL_INIT_LIST (&(c->rq), fields); +#ifdef MHD_SUPPORT_POST_PARSER + mhd_DLINKEDL_INIT_LIST (&(c->rq), post_fields); +#endif /* MHD_SUPPORT_POST_PARSER */ + c->rq.version = NULL; + c->rq.url = NULL; + c->rq.field_lines.start = NULL; + c->rq.app_context = NULL; + c->rq.hdrs.rq_line.rq_tgt = NULL; + c->rq.hdrs.rq_line.rq_tgt_qmark = NULL; + + // TODO: move reply reset to special function + c->rp.app_act_ctx.connection = NULL; + c->rp.response = NULL; + c->rp.resp_iov.iov = NULL; +#endif /* ! HAVE_NULL_PTR_ALL_ZEROS */ c->write_buffer = NULL; c->write_buffer_size = 0;