about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/if_index.c
diff options
context:
space:
mode:
authorSteve Ellcey <sellcey@caviumnetworks.com>2017-11-15 08:58:48 -0800
committerSteve Ellcey <sellcey@caviumnetworks.com>2017-11-15 08:58:48 -0800
commit2180fee114b778515b3f560e5ff1e795282e60b0 (patch)
treef6c4c852095296d6d95885254e2582e96e028cce /sysdeps/unix/sysv/linux/if_index.c
parentcad7ca390879f2a8250e58bf5009a00b887a19b7 (diff)
downloadglibc-2180fee114b778515b3f560e5ff1e795282e60b0.tar.gz
glibc-2180fee114b778515b3f560e5ff1e795282e60b0.tar.xz
glibc-2180fee114b778515b3f560e5ff1e795282e60b0.zip
Check length of ifname before copying it into to ifreq structure.
	[BZ #22442]
	* sysdeps/unix/sysv/linux/if_index.c (__if_nametoindex):
	Check if ifname is too long.
Diffstat (limited to 'sysdeps/unix/sysv/linux/if_index.c')
-rw-r--r--sysdeps/unix/sysv/linux/if_index.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index 56f3f136cb..e7ca27bc18 100644
--- a/sysdeps/unix/sysv/linux/if_index.c
+++ b/sysdeps/unix/sysv/linux/if_index.c
@@ -43,6 +43,12 @@ __if_nametoindex (const char *ifname)
   if (fd < 0)
     return 0;
 
+  if (strlen (ifname) >= IFNAMSIZ)
+    {
+      __set_errno (ENODEV);
+      return 0;
+    }
+
   strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
   if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
     {