Browse Source

jail: netifd: check target netns fd before using it

Make sure filehandler is non-negative before using it.

Coverity CID: 1492888 Negative returns
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle 2 years ago
parent
commit
e1d7cee59b
1 changed files with 4 additions and 0 deletions
  1. 4 0
      jail/netifd.c

+ 4 - 0
jail/netifd.c

@@ -469,6 +469,10 @@ int jail_network_start(struct ubus_context *new_ctx, char *new_jail_name, pid_t
 	watch_ubus_service();
 
 	netns_fd = ns_open_pid("net", ns_pid);
+	if (netns_fd < 0) {
+		ret = ESRCH;
+		goto errout_inotify;
+	}
 
 	netns_updown(host_ubus_ctx, jail_name, true, netns_fd);