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