get_time_rtt() parses with strtoul, so "-1" wraps and "4294968s" comes out as 705ms. Parse with strtoll and refuse negatives and values past UINT_MAX. Fixes: 54e0b2e71d72 ("rto support for ip command") Signed-off-by: Andrii Tereshchenko --- rtt 4294968s: was rtt 705ms, now "rtt" value is invalid. lib/utils.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index b23d8dd5..62e4887e 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -260,32 +260,22 @@ int get_float_min_max(float *val, const char *arg, float min, float max) int get_time_rtt(unsigned int *val, const char *arg, int *raw) { double t; - unsigned long res; + long long res; char *p; if (strchr(arg, '.') != NULL) { t = strtod(arg, &p); - if (t < 0.0) - return -1; /* no digits? */ if (!p || p == arg) return -1; - - /* over/underflow */ - if ((t == HUGE_VALF || t == HUGE_VALL) && errno == ERANGE) - return -1; } else { - res = strtoul(arg, &p, 0); + res = strtoll(arg, &p, 0); /* empty string? */ if (!p || p == arg) return -1; - /* overflow */ - if (res == ULONG_MAX && errno == ERANGE) - return -1; - t = (double)res; } @@ -307,6 +297,9 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw) return -1; } + if (t < 0 || t > UINT_MAX) + return -ERANGE; + /* emulate ceil() without having to bring-in -lm and always be >= 1 */ *val = t; if (*val < t) base-commit: 06b62d179bbb5b62cba965dcda48a613dbc59416 -- 2.53.0