[PATCH 04/28] batctl: use strict interval/timeout parsing
Sven Eckelmann <[email protected]> Sun, 21 Jun 2026 16:23:54 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
The sscanf() function does not only return 0 when the value could not be
parsed from the string. Also EOF is a potential return value. To make the
check more strict, just compare the returned value with the expected number
of scanned/parsed items.
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 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/debug.c b/debug.c
index 163a46b..5bf6d5f 100644
--- a/debug.c
+++ b/debug.c
@@ -68,7 +68,7 @@ int handle_debug_table(struct state *state, int argc, char **argv)
break;
}
- if (!sscanf(optarg, "%f", &watch_interval)) {
+ if (sscanf(optarg, "%f", &watch_interval) != 1) {
fprintf(stderr,
"Error - provided argument of '-%c' is not a number\n",
optchar);
@@ -83,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)) {
+ if (sscanf(optarg, "%f", &orig_timeout) != 1) {
fprintf(stderr,
"Error - provided argument of '-%c' is not a number\n",
optchar);
--
2.47.3