[PATCH 3/5] batctl: debug: reject trailing garbage for intervals

Sven Eckelmann <[email protected]> Sat, 04 Jul 2026 21:36:01 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
 A "%f" sscanf conversion stops at the first
character it cannot consume and reports success for the leading numeric
part, so trailing garbag are still accepted silently.

Append a "%c" conversion so any trailing character makes sscanf() report
more than the one expected item.

Fixes: 302a41a73915 ("batctl: Add timeout filtering option for originators")
Fixes: e4a7b7733faf ("batctl: Add an optional interval for watch-mode")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 debug.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/debug.c b/debug.c
index ae13dce..1cceea6 100644
--- a/debug.c
+++ b/debug.c
@@ -51,6 +51,7 @@ int handle_debug_table(struct state *state, int argc, char **argv)
 	float watch_interval = 1;
 	char *orig_iface = NULL;
 	int optchar;
+	char tmp;
 	int err;
 
 	while ((optchar = getopt(argc, argv, "hnw::t:Humi:")) != -1) {
@@ -67,7 +68,7 @@ int handle_debug_table(struct state *state, int argc, char **argv)
 			if (!optarg)
 				break;
 
-			if (sscanf(optarg, "%f", &watch_interval) != 1) {
+			if (sscanf(optarg, "%f%c", &watch_interval, &tmp) != 1) {
 				fprintf(stderr,
 					"Error - provided argument of '-%c' is not a number\n",
 					optchar);
@@ -82,7 +83,7 @@ int handle_debug_table(struct state *state, int argc, char **argv)
 			}
 
 			read_opt |= NO_OLD_ORIGS;
-			if (sscanf(optarg, "%f", &orig_timeout) != 1) {
+			if (sscanf(optarg, "%f%c", &orig_timeout, &tmp) != 1) {
 				fprintf(stderr,
 					"Error - provided argument of '-%c' is not a number\n",
 					optchar);

-- 
2.47.3