summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Härdeman2025-11-23 18:34:51 +0000
committerÁlvaro Fernández Rojas2025-11-23 19:04:00 +0000
commit9b9ea96ca90e736d0668bfa6c3011c36efabbc8d (patch)
treebb732b2590a81001c887b5b6eb7318eaedccd0af
parent9830e5e2bf375a7b74fa4ffc72330fccf0da6097 (diff)
downloadodhcpd-9b9ea96ca90e736d0668bfa6c3011c36efabbc8d.tar.gz
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 <david@hardeman.nu> Link: https://github.com/openwrt/odhcpd/pull/322 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
-rw-r--r--src/statefiles.c2
1 files changed, 1 insertions, 1 deletions
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);