* [PATCH iproute2 1/1] ip netns: use strtol() instead of atoi()
@ 2017-10-27 16:55 Roman Mashak
2017-10-31 16:31 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Roman Mashak @ 2017-10-27 16:55 UTC (permalink / raw)
To: stephen; +Cc: netdev, jhs, Roman Mashak
Use strtol-based API to parse and validate integer input; atoi() does not detect
errors and may yield undefined behaviour if result can't be represented.
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
---
ip/ipnetns.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index afb4978..96da040 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -711,7 +711,8 @@ static int netns_set(int argc, char **argv)
return -1;
}
name = argv[0];
- nsid = atoi(argv[1]);
+ if (get_integer(&nsid, argv[1], 0))
+ invarg("Invalid \"netnsid\" value\n", argv[1]);
snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name);
netns = open(netns_path, O_RDONLY | O_CLOEXEC);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 1/1] ip netns: use strtol() instead of atoi()
2017-10-27 16:55 [PATCH iproute2 1/1] ip netns: use strtol() instead of atoi() Roman Mashak
@ 2017-10-31 16:31 ` Stephen Hemminger
2017-10-31 18:01 ` Roman Mashak
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2017-10-31 16:31 UTC (permalink / raw)
To: Roman Mashak; +Cc: netdev, jhs
On Fri, 27 Oct 2017 12:55:27 -0400
Roman Mashak <mrv@mojatatu.com> wrote:
> Use strtol-based API to parse and validate integer input; atoi() does not detect
> errors and may yield undefined behaviour if result can't be represented.
>
> Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Since network namespace is really an unsigned value, shouldn't it be
using get_unsigned?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 1/1] ip netns: use strtol() instead of atoi()
2017-10-31 16:31 ` Stephen Hemminger
@ 2017-10-31 18:01 ` Roman Mashak
0 siblings, 0 replies; 3+ messages in thread
From: Roman Mashak @ 2017-10-31 18:01 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, jhs
Stephen Hemminger <stephen@networkplumber.org> writes:
> On Fri, 27 Oct 2017 12:55:27 -0400
> Roman Mashak <mrv@mojatatu.com> wrote:
>
>> Use strtol-based API to parse and validate integer input; atoi() does not detect
>> errors and may yield undefined behaviour if result can't be represented.
>>
>> Signed-off-by: Roman Mashak <mrv@mojatatu.com>
>
> Since network namespace is really an unsigned value, shouldn't it be
> using get_unsigned?
Agree, I will resend v2.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-31 18:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-27 16:55 [PATCH iproute2 1/1] ip netns: use strtol() instead of atoi() Roman Mashak
2017-10-31 16:31 ` Stephen Hemminger
2017-10-31 18:01 ` Roman Mashak
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).