[PATCH 08/11] batctl: ping: reject invalid timeout argument
Sven Eckelmann <[email protected]> Tue, 07 Jul 2026 20:46:50 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
The -t option parses its argument with strtol and defines a lower limit of
1. But it ignores any invalid parameter silently.
Use the same strto* validation as the rest of batctl and print a user
readable error in case of an parsing error.
Fixes: 2474249a6312 ("[batctl] ping utility updated to latest batman adv")
Signed-off-by: Sven Eckelmann <[email protected]>
---
ping.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/ping.c b/ping.c
index 5551cd4..7ba872a 100644
--- a/ping.c
+++ b/ping.c
@@ -128,9 +128,16 @@ static int ping(struct state *state, int argc, char **argv)
loop_interval.tv_nsec = (long)(fractional_part * 1000000000l);
break;
case 't':
- timeout = strtol(optarg, NULL, 10);
- if (timeout < 1)
- timeout = 1;
+ tmp = strtol(optarg, &endptr, 10);
+ if (!endptr || *endptr != '\0' || endptr == optarg ||
+ tmp < 1 || tmp > INT_MAX) {
+ fprintf(stderr,
+ "Error - the supplied timeout is invalid: %s\n",
+ optarg);
+ ping_usage();
+ return EXIT_FAILURE;
+ }
+ timeout = tmp;
break;
case 'R':
rr = 1;
--
2.47.3