mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-08-14 05:16:11 +00:00
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>
This commit is contained in:
parent
e348889289
commit
acbe9118ce
@ -700,7 +700,8 @@ static int netns_set(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
char netns_path[PATH_MAX];
|
char netns_path[PATH_MAX];
|
||||||
const char *name;
|
const char *name;
|
||||||
int netns, nsid;
|
unsigned int nsid;
|
||||||
|
int netns;
|
||||||
|
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
fprintf(stderr, "No netns name specified\n");
|
fprintf(stderr, "No netns name specified\n");
|
||||||
@ -711,7 +712,8 @@ static int netns_set(int argc, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
name = argv[0];
|
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);
|
snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name);
|
||||||
netns = open(netns_path, O_RDONLY | O_CLOEXEC);
|
netns = open(netns_path, O_RDONLY | O_CLOEXEC);
|
||||||
|
Loading…
Reference in New Issue
Block a user