]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip netns: use strtol() instead of atoi()
authorRoman Mashak <mrv@mojatatu.com>
Tue, 31 Oct 2017 18:24:19 +0000 (14:24 -0400)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 1 Nov 2017 21:06:05 +0000 (22:06 +0100)
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>
ip/ipnetns.c

index afb4978a5be7da0caa5f5993d8f8d5ff0d960208..bad7933188e6d0ba604636e0759ab7a44d41bbae 100644 (file)
@@ -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);