aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Mashak <mrv@mojatatu.com>2017-10-31 14:24:19 -0400
committerStephen Hemminger <stephen@networkplumber.org>2017-11-01 22:06:05 +0100
commitacbe9118ce8086f765ffb0da15f80c7c01a8903a (patch)
tree0d2e501ef522e2e96eec066c2f05d6e0f709248b
parente3488892897dbd4c7b33f7899f768c75893aff6d (diff)
downloadplatform_external_iproute2-acbe9118ce8086f765ffb0da15f80c7c01a8903a.tar.gz
platform_external_iproute2-acbe9118ce8086f765ffb0da15f80c7c01a8903a.tar.bz2
platform_external_iproute2-acbe9118ce8086f765ffb0da15f80c7c01a8903a.zip
ip netns: use strtol() instead of atoi()
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. v2: use get_unsigned() since network namespace is really an unsigned value. Signed-off-by: Roman Mashak <mrv@mojatatu.com>
-rw-r--r--ip/ipnetns.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index afb4978a..bad79331 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -700,7 +700,8 @@ static int netns_set(int argc, char **argv)
{
char netns_path[PATH_MAX];
const char *name;
- int netns, nsid;
+ unsigned int nsid;
+ int netns;
if (argc < 1) {
fprintf(stderr, "No netns name specified\n");
@@ -711,7 +712,8 @@ static int netns_set(int argc, char **argv)
return -1;
}
name = argv[0];
- nsid = atoi(argv[1]);
+ if (get_unsigned(&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);