From 9b9ea96ca90e736d0668bfa6c3011c36efabbc8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Sun, 23 Nov 2025 19:34:51 +0100 Subject: [PATCH] statefiles: fix off-by-one-bug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The string with the final hostsfile name is "%s.%s", so we need two extra bytes for the separating "." and for the trailing null byte. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/322 Signed-off-by: Álvaro Fernández Rojas --- src/statefiles.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/statefiles.c b/src/statefiles.c index ed45f55..a5d4e3e 100644 --- a/src/statefiles.c +++ b/src/statefiles.c @@ -103,7 +103,7 @@ static void statefiles_write_hosts(time_t now) avl_for_each_element(&interfaces, ctxt.iface, avl) { char *hostsfile; - hostsfile = alloca(strlen(ODHCPD_HOSTS_FILE_PREFIX) + strlen(ctxt.iface->name) + 1); + hostsfile = alloca(strlen(ODHCPD_HOSTS_FILE_PREFIX) + 1 + strlen(ctxt.iface->name) + 1); sprintf(hostsfile, "%s.%s", ODHCPD_HOSTS_FILE_PREFIX, ctxt.iface->name); fd = openat(config.dhcp_hostsdir_fd, tmp_hostsfile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644); -- 2.30.2