netns: more input validation

ip netns accepts invalid input as namespace name like an empty string or a
string longer than the maximum file name length.
Check that the netns name is not empty and less than or equal to NAME_MAX.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
This commit is contained in:
Matteo Croce 2017-07-25 15:30:31 +02:00 committed by Stephen Hemminger
parent c2a85c3bcd
commit d3f0b09197
1 changed files with 2 additions and 1 deletions

View File

@ -768,7 +768,8 @@ static int netns_monitor(int argc, char **argv)
static int invalid_name(const char *name)
{
return strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
return !*name || strlen(name) > NAME_MAX ||
strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
}
int do_netns(int argc, char **argv)