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