Instead of ibuf_reserve() just use ibuf_add_zero(buf, 1) to add a NUL byte to the buffer.
There is more needed in here but lets start small. -- :wq Claudio Index: check_tcp.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/check_tcp.c,v retrieving revision 1.58 diff -u -p -r1.58 check_tcp.c --- check_tcp.c 18 Sep 2021 19:44:46 -0000 1.58 +++ check_tcp.c 10 Jun 2023 07:36:17 -0000 @@ -344,17 +344,14 @@ check_http_code(struct ctl_tcp_event *ct char *head; char scode[4]; const char *estr; - u_char *b; int code; struct host *host; /* * ensure string is nul-terminated. */ - b = ibuf_reserve(cte->buf, 1); - if (b == NULL) + if (ibuf_add_zero(cte->buf, 1) == -1) fatal("out of memory"); - *b = '\0'; head = cte->buf->buf; host = cte->host; @@ -398,17 +395,14 @@ int check_http_digest(struct ctl_tcp_event *cte) { char *head; - u_char *b; char digest[SHA1_DIGEST_STRING_LENGTH]; struct host *host; /* * ensure string is nul-terminated. */ - b = ibuf_reserve(cte->buf, 1); - if (b == NULL) + if (ibuf_add_zero(cte->buf, 1) == -1) fatal("out of memory"); - *b = '\0'; head = cte->buf->buf; host = cte->host;