[PATCH 1/6] alfred: fix off-by-one in client interface name length checks
Sven Eckelmann <[email protected]> Fri, 31 Jul 2026 13:44:50 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
check_interface(), alfred_client_change_interface() and
alfred_client_change_bat_iface() rejected names only when they were
strictly longer than the destination buffer. A name whose length equals the
buffer size passed the check, but the subsequent strncpy() then filled the
buffer without a terminator and the forced '\0' at the last position
silently dropped the final character.
Reject names which don't fit including their terminating \0 byte.
Fixes: babd772a36e1 ("alfred: support for changing interfaces")
Fixes: b96cc742ef3e ("alfred: introduce 'change batman-adv interface' IPC call")
Fixes: 67ae5f57eedd ("alfred: Add support for multiple interfaces per master")
Signed-off-by: Sven Eckelmann <[email protected]>
---
client.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/client.c b/client.c
index 9fa9f00..f56042a 100644
--- a/client.c
+++ b/client.c
@@ -222,7 +222,7 @@ static int check_interface(const char *iface)
struct ifreq ifr;
int sock = -1;
- if (strlen(iface) > IFNAMSIZ) {
+ if (strlen(iface) >= IFNAMSIZ) {
fprintf(stderr, "%s: interface name list too long, not changing\n",
__func__);
return -1;
@@ -262,7 +262,7 @@ int alfred_client_change_interface(struct globals *globals)
return -1;
interface_len = strlen(globals->net_iface);
- if (interface_len > sizeof(change_interface.ifaces)) {
+ if (interface_len >= sizeof(change_interface.ifaces)) {
fprintf(stderr, "%s: interface name list too long, not changing\n",
__func__);
return 0;
@@ -311,7 +311,7 @@ int alfred_client_change_bat_iface(struct globals *globals)
return -1;
interface_len = strlen(globals->mesh_iface);
- if (interface_len > sizeof(change_bat_iface.bat_iface)) {
+ if (interface_len >= sizeof(change_bat_iface.bat_iface)) {
fprintf(stderr, "%s: batman-adv interface name list too long, not changing\n",
__func__);
return 0;
--
2.47.3