From: Stephen Hemminger Date: Thu, 29 Mar 2018 15:40:26 +0000 (-0700) Subject: namespace: limit the length of namespace name to avoid snprintf overflow X-Git-Tag: v4.16.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89e3c36b066d7fe9bd90a4740cc7aa4d859f0dda;p=thirdparty%2Fiproute2.git namespace: limit the length of namespace name to avoid snprintf overflow This fixes problem reported by gcc-8 Signed-off-by: Stephen Hemminger --- diff --git a/lib/namespace.c b/lib/namespace.c index 6f3356d0f..43e0fe349 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -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)