aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Dichtel <nicolas.dichtel@6wind.com>2023-05-11 16:42:24 +0200
committerStephen Hemminger <stephen@networkplumber.org>2023-05-11 14:11:43 -0700
commit465e87a89c134d28a7fae540d26b27e6a2e1d6c0 (patch)
tree6935f265cc4aa40b832f3d5e3ee7ae098e021632
parent2905e783479d873c17ab4cb270161a139ccb7f1e (diff)
downloadiproute2-465e87a89c134d28a7fae540d26b27e6a2e1d6c0.tar.gz
ipnetns: fix fd leak with 'ip netns set'
There is no reason to open this netns file. set_netnsid_from_name() uses netns_get_fd() for this purpose and uses the returned fd. Reported-by: Stephen Hemminger <stephen@networkplumber.org> Fixes: d182ee1307c7 ("ipnetns: allow to get and set netns ids") Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--ip/ipnetns.c11
1 files changed, 1 insertions, 10 deletions
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 120353491..9d996832a 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -967,9 +967,8 @@ int set_netnsid_from_name(const char *name, int nsid)
static int netns_set(int argc, char **argv)
{
- char netns_path[PATH_MAX];
const char *name;
- int netns, nsid;
+ int nsid;
if (argc < 1) {
fprintf(stderr, "No netns name specified\n");
@@ -988,14 +987,6 @@ static int netns_set(int argc, char **argv)
else if (nsid < 0)
invarg("\"netnsid\" value should be >= 0", argv[1]);
- snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name);
- netns = open(netns_path, O_RDONLY | O_CLOEXEC);
- if (netns < 0) {
- fprintf(stderr, "Cannot open network namespace \"%s\": %s\n",
- name, strerror(errno));
- return -1;
- }
-
return set_netnsid_from_name(name, nsid);
}