From: Rafael Sadowski Subject: Re: httpd: remove MAX_IMSG_DATA_SIZE To: tech@openbsd.org Date: Sat, 17 Oct 2026 09:03:48 +0200 On Sat Oct 17, 2026 at 09:02:27AM +0200, Rafael Sadowski wrote: > Remove MAX_IMSG_DATA_SIZE and we avoid having to calculate the length > over and over again in a loop. > > OK? > Full diff ... commit ff40a9b7c2f4879c791074d9e609ed97c8e28781 Author: Rafael Sadowski Date: Sat Oct 17 08:59:57 2026 +0200 httpd: remove MAX_IMSG_DATA_SIZE diff --git a/config.c b/config.c index 957da66..23a7042 100644 --- a/config.c +++ b/config.c @@ -320,7 +320,7 @@ config_settls(struct httpd *env, struct server *srv, enum tls_config_type type, struct server_config *srv_conf = &srv->srv_conf; struct tls_config tls; struct iovec iov[2]; - size_t c; + size_t c, maxchunk; if (data == NULL || len == 0) return (0); @@ -335,10 +335,13 @@ config_settls(struct httpd *env, struct server *srv, enum tls_config_type type, tls.tls_len = len; tls.tls_chunk_offset = 0; + /* largest chunk that fits next to the header into one imsg */ + maxchunk = MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(tls); + while (len > 0) { tls.tls_chunk_len = len; - if (tls.tls_chunk_len > (MAX_IMSG_DATA_SIZE - sizeof(tls))) - tls.tls_chunk_len = MAX_IMSG_DATA_SIZE - sizeof(tls); + if (tls.tls_chunk_len > maxchunk) + tls.tls_chunk_len = maxchunk; c = 0; iov[c].iov_base = &tls; diff --git a/httpd.h b/httpd.h index e238e04..381f8da 100644 --- a/httpd.h +++ b/httpd.h @@ -165,7 +165,6 @@ struct imsgev { }; #define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE) -#define MAX_IMSG_DATA_SIZE (MAX_IMSGSIZE - IMSG_HEADER_SIZE) enum imsg_type { IMSG_NONE,