namespace: limit the length of namespace name to avoid snprintf overflow

This fixes problem reported by gcc-8

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Stephen Hemminger 2018-03-29 08:40:26 -07:00
parent 08a93b32f5
commit 89e3c36b06
1 changed files with 4 additions and 1 deletions

View File

@ -17,12 +17,15 @@
static void bind_etc(const char *name)
{
char etc_netns_path[PATH_MAX];
char etc_netns_path[sizeof(NETNS_ETC_DIR) + NAME_MAX];
char netns_name[PATH_MAX];
char etc_name[PATH_MAX];
struct dirent *entry;
DIR *dir;
if (strlen(name) >= NAME_MAX)
return;
snprintf(etc_netns_path, sizeof(etc_netns_path), "%s/%s", NETNS_ETC_DIR, name);
dir = opendir(etc_netns_path);
if (!dir)