077c9d
commit d527c860f5a3f0ed687bd03f0cb464612dc23408
077c9d
Author: Florian Weimer <fweimer@redhat.com>
077c9d
Date:   Tue Nov 27 16:12:43 2018 +0100
077c9d
077c9d
    CVE-2018-19591: if_nametoindex: Fix descriptor for overlong name [BZ #23927]
077c9d
077c9d
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
077c9d
index e3d08982d9931108..782fc5e1750e9ead 100644
077c9d
--- a/sysdeps/unix/sysv/linux/if_index.c
077c9d
+++ b/sysdeps/unix/sysv/linux/if_index.c
077c9d
@@ -38,11 +38,6 @@ __if_nametoindex (const char *ifname)
077c9d
   return 0;
077c9d
 #else
077c9d
   struct ifreq ifr;
077c9d
-  int fd = __opensock ();
077c9d
-
077c9d
-  if (fd < 0)
077c9d
-    return 0;
077c9d
-
077c9d
   if (strlen (ifname) >= IFNAMSIZ)
077c9d
     {
077c9d
       __set_errno (ENODEV);
077c9d
@@ -50,6 +45,12 @@ __if_nametoindex (const char *ifname)
077c9d
     }
077c9d
 
077c9d
   strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
077c9d
+
077c9d
+  int fd = __opensock ();
077c9d
+
077c9d
+  if (fd < 0)
077c9d
+    return 0;
077c9d
+
077c9d
   if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
077c9d
     {
077c9d
       int saved_errno = errno;