Negative values are invalid netns ids. Ensure that helper functions
don't accidentally try to process them.
Signed-off-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
static struct nsid_cache *netns_map_get_by_nsid(int nsid)
{
static struct nsid_cache *netns_map_get_by_nsid(int nsid)
{
- uint32_t h = NSID_HASH_NSID(nsid);
+ uint32_t h;
+
+ if (nsid < 0)
+ return NULL;
+ h = NSID_HASH_NSID(nsid);
hlist_for_each(n, &nsid_head[h]) {
struct nsid_cache *c = container_of(n, struct nsid_cache,
nsid_hash);
hlist_for_each(n, &nsid_head[h]) {
struct nsid_cache *c = container_of(n, struct nsid_cache,
nsid_hash);
+ if (nsid < 0)
+ return NULL;
+
netns_nsid_socket_init();
netns_map_init();
netns_nsid_socket_init();
netns_map_init();
+ if (nsid < 0)
+ return -EINVAL;
+
dir = opendir(NETNS_RUN_DIR);
if (!dir)
return -ENOENT;
dir = opendir(NETNS_RUN_DIR);
if (!dir)
return -ENOENT;
continue;
id = get_netnsid_from_name(entry->d_name);
continue;
id = get_netnsid_from_name(entry->d_name);
+ if (id >= 0 && nsid == id) {
strcpy(name, entry->d_name);
closedir(dir);
return 0;
strcpy(name, entry->d_name);
closedir(dir);
return 0;