From dcedda3fb2b1c07b1e144aa309ff524f2d919ea3 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 2 Dec 2021 16:28:42 -0800 Subject: [PATCH] Fix overflow check for strtod and strtoul --- lib/utils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index cfe0e2e9..f4109413 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -228,6 +228,7 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw) char *p; if (strchr(arg, '.') != NULL) { + errno = 0; t = strtod(arg, &p); if (t < 0.0) return -1; @@ -237,9 +238,10 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw) return -1; /* over/underflow */ - if ((t == HUGE_VALF || t == HUGE_VALL) && errno == ERANGE) + if (errno == ERANGE) return -1; } else { + errno = 0; res = strtoul(arg, &p, 0); /* empty string? */ @@ -247,7 +249,7 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw) return -1; /* overflow */ - if (res == ULONG_MAX && errno == ERANGE) + if (errno == ERANGE) return -1; t = (double)res; -- 2.44.0