summaryrefslogtreecommitdiff
path: root/pkg/iproute2/patch/0013-Fix-overflow-check-for-strtod-and-strtoul.patch
blob: eb028b328a0f59e9e2e12adb8f091655f243e62a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From dcedda3fb2b1c07b1e144aa309ff524f2d919ea3 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
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