1From dcedda3fb2b1c07b1e144aa309ff524f2d919ea3 Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Thu, 2 Dec 2021 16:28:42 -0800
4Subject: [PATCH] Fix overflow check for strtod and strtoul
5
6---
7 lib/utils.c | 6 ++++--
8 1 file changed, 4 insertions(+), 2 deletions(-)
9
10diff --git a/lib/utils.c b/lib/utils.c
11index cfe0e2e9..f4109413 100644
12--- a/lib/utils.c
13+++ b/lib/utils.c
14@@ -228,6 +228,7 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw)
15 char *p;
16
17 if (strchr(arg, '.') != NULL) {
18+ errno = 0;
19 t = strtod(arg, &p);
20 if (t < 0.0)
21 return -1;
22@@ -237,9 +238,10 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw)
23 return -1;
24
25 /* over/underflow */
26- if ((t == HUGE_VALF || t == HUGE_VALL) && errno == ERANGE)
27+ if (errno == ERANGE)
28 return -1;
29 } else {
30+ errno = 0;
31 res = strtoul(arg, &p, 0);
32
33 /* empty string? */
34@@ -247,7 +249,7 @@ int get_time_rtt(unsigned int *val, const char *arg, int *raw)
35 return -1;
36
37 /* overflow */
38- if (res == ULONG_MAX && errno == ERANGE)
39+ if (errno == ERANGE)
40 return -1;
41
42 t = (double)res;
43--
442.44.0
45