[PATCH iproute2 v2 1/1] ip netns: use strtol() instead of atoi()

Subsystems: the rest

STALE3205d

2 messages, 2 authors, 2017-11-01 · open the first message on its own page

[PATCH iproute2 v2 1/1] ip netns: use strtol() instead of atoi()

From: Roman Mashak <hidden>
Date: 2017-10-31 18:24:27

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 <redacted>
---
 ip/ipnetns.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index afb4978..bad7933 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);
-- 
1.9.1

Re: [PATCH iproute2 v2 1/1] ip netns: use strtol() instead of atoi()

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2017-11-01 21:07:07

On Tue, 31 Oct 2017 14:24:19 -0400
Roman Mashak [off-list ref] 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.

v2: use get_unsigned() since network namespace is really an unsigned value.

Signed-off-by: Roman Mashak <redacted>
Applied. Thanks Roman
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help