* [iproute2 PATCH] utils: fix hex digits parsing in hexstring_a2n()
@ 2016-06-14 20:55 Beniamino Galvani
0 siblings, 0 replies; 2+ messages in thread
From: Beniamino Galvani @ 2016-06-14 20:55 UTC (permalink / raw)
To: netdev, Stephen Hemminger
strtoul() only modifies errno on overflow, so if errno is not zero
before calling the function its value is preserved and makes the
function fail for valid inputs; initialize it.
Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
---
lib/utils.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/utils.c b/lib/utils.c
index 70e85b7..7dceeb5 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -924,6 +924,7 @@ __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len)
strncpy(tmpstr, str, 2);
tmpstr[2] = '\0';
+ errno = 0;
tmp = strtoul(tmpstr, &endptr, 16);
if (errno != 0 || tmp > 0xFF || *endptr != '\0')
return NULL;
--
2.5.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
[parent not found: <80a1168c78944f39ab2b270df68ad9e5@HQ1WP-EXMB11.corp.brocade.com>]
* Re: [iproute2 PATCH] utils: fix hex digits parsing in hexstring_a2n()
[not found] <80a1168c78944f39ab2b270df68ad9e5@HQ1WP-EXMB11.corp.brocade.com>
@ 2016-06-14 21:25 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2016-06-14 21:25 UTC (permalink / raw)
To: Beniamino Galvani; +Cc: netdev@vger.kernel.org
On Tue, 14 Jun 2016 20:55:17 +0000
Beniamino Galvani <bgalvani@redhat.com> wrote:
> strtoul() only modifies errno on overflow, so if errno is not zero
> before calling the function its value is preserved and makes the
> function fail for valid inputs; initialize it.
>
> Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
> ---
> lib/utils.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/utils.c b/lib/utils.c
> index 70e85b7..7dceeb5 100644
> --- a/lib/utils.c
> +++ b/lib/utils.c
> @@ -924,6 +924,7 @@ __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len)
>
> strncpy(tmpstr, str, 2);
> tmpstr[2] = '\0';
> + errno = 0;
> tmp = strtoul(tmpstr, &endptr, 16);
> if (errno != 0 || tmp > 0xFF || *endptr != '\0')
> return NULL;
Applied.
The code here is doing things in a manner much harder than necessary...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-06-14 21:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-14 20:55 [iproute2 PATCH] utils: fix hex digits parsing in hexstring_a2n() Beniamino Galvani
[not found] <80a1168c78944f39ab2b270df68ad9e5@HQ1WP-EXMB11.corp.brocade.com>
2016-06-14 21:25 ` Stephen Hemminger
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).