* [PATCH v2] iproute2: lib/utils.c bug fixes
@ 2013-04-14 14:10 Dash Four
2013-04-14 17:00 ` Stephen Hemminger
2013-04-14 19:22 ` David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Dash Four @ 2013-04-14 14:10 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger
This patch fixes the following 3 bugs in get_u32/get_u64 functions:
1. On 32-bit systems, get_u32 could not detect an overflow.
get_u32(&l, "4294967296", 10) always returned 4294967295
(ULONG_MAX on 32-bit systems).
2. get_u64(&ll, "4294967295", 10) was returning an error where
it shouldn't have (4294967295 is perfectly legitimate value for
unsigned long long).
3. get_u64 couldn't detect an overflow errors (arg > ULLONG_MAX)
Changelog:
v2 - Dropped name title from Developer Certificate of Origin
Signed-off-by: Dash Four <mr.dash.four@googlemail.com>
---
lib/utils.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/utils.c b/lib/utils.c
index 5bcdbcf..aeee8f1 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -149,10 +149,12 @@ int get_u64(__u64 *val, const char *arg, int base)
unsigned long long res;
char *ptr;
+ errno = 0;
+
if (!arg || !*arg)
return -1;
res = strtoull(arg, &ptr, base);
- if (!ptr || ptr == arg || *ptr || res == 0xFFFFFFFFULL)
+ if (!ptr || ptr == arg || *ptr || (res == ULLONG_MAX && errno == ERANGE))
return -1;
*val = res;
return 0;
@@ -163,10 +165,12 @@ int get_u32(__u32 *val, const char *arg, int base)
unsigned long res;
char *ptr;
+ errno = 0;
+
if (!arg || !*arg)
return -1;
res = strtoul(arg, &ptr, base);
- if (!ptr || ptr == arg || *ptr || res > 0xFFFFFFFFUL)
+ if (!ptr || ptr == arg || *ptr || res > 0xFFFFFFFFUL || errno == ERANGE)
return -1;
*val = res;
return 0;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] iproute2: lib/utils.c bug fixes
2013-04-14 14:10 [PATCH v2] iproute2: lib/utils.c bug fixes Dash Four
@ 2013-04-14 17:00 ` Stephen Hemminger
2013-04-14 19:34 ` Dash Four
2013-04-14 19:22 ` David Miller
1 sibling, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2013-04-14 17:00 UTC (permalink / raw)
To: Dash Four; +Cc: netdev
On Sun, 14 Apr 2013 15:10:54 +0100
Dash Four <mr.dash.four@googlemail.com> wrote:
> This patch fixes the following 3 bugs in get_u32/get_u64 functions:
>
> 1. On 32-bit systems, get_u32 could not detect an overflow.
> get_u32(&l, "4294967296", 10) always returned 4294967295
> (ULONG_MAX on 32-bit systems).
>
> 2. get_u64(&ll, "4294967295", 10) was returning an error where
> it shouldn't have (4294967295 is perfectly legitimate value for
> unsigned long long).
>
> 3. get_u64 couldn't detect an overflow errors (arg > ULLONG_MAX)
>
> Changelog:
>
> v2 - Dropped name title from Developer Certificate of Origin
>
> Signed-off-by: Dash Four <mr.dash.four@googlemail.com>
> ---
> lib/utils.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
Thanks for your patch. there were lots of related over/underflow errors in
this code which have existed for a long time. I took your patch as motivation
and did multiple fixes to add error checking for all the cases present.
Thank you.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] iproute2: lib/utils.c bug fixes
2013-04-14 14:10 [PATCH v2] iproute2: lib/utils.c bug fixes Dash Four
2013-04-14 17:00 ` Stephen Hemminger
@ 2013-04-14 19:22 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2013-04-14 19:22 UTC (permalink / raw)
To: mr.dash.four; +Cc: netdev, stephen
From: Dash Four <mr.dash.four@googlemail.com>
Date: Sun, 14 Apr 2013 15:10:54 +0100
> This patch fixes the following 3 bugs in get_u32/get_u64 functions:
>
> 1. On 32-bit systems, get_u32 could not detect an overflow.
> get_u32(&l, "4294967296", 10) always returned 4294967295
> (ULONG_MAX on 32-bit systems).
>
> 2. get_u64(&ll, "4294967295", 10) was returning an error where
> it shouldn't have (4294967295 is perfectly legitimate value for
> unsigned long long).
>
> 3. get_u64 couldn't detect an overflow errors (arg > ULLONG_MAX)
>
> Changelog:
>
> v2 - Dropped name title from Developer Certificate of Origin
>
> Signed-off-by: Dash Four <mr.dash.four@googlemail.com>
Stephen already reimplmeneted your fixes in a slightly different
way.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-04-14 19:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-14 14:10 [PATCH v2] iproute2: lib/utils.c bug fixes Dash Four
2013-04-14 17:00 ` Stephen Hemminger
2013-04-14 19:34 ` Dash Four
2013-04-14 19:37 ` David Miller
2013-04-14 19:22 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).