From: David Härdeman Date: Sun, 23 Nov 2025 18:34:51 +0000 (+0100) Subject: statefiles: fix off-by-one-bug X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=9b9ea96ca90e736d0668bfa6c3011c36efabbc8d;p=project%2Fodhcpd.git statefiles: fix off-by-one-bug 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 --- 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);