about summary refs log tree commit diff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-11-27 16:12:43 +0100
committerFlorian Weimer <fweimer@redhat.com>2018-11-27 18:40:56 +0100
commitce6ba630dbc96f49eb1f30366aa62261df4792f9 (patch)
tree5151818a89dc1cd3d1c9d5082ab03f6716dd4036 /sysdeps/unix
parentf5cc21eaeea6afbdfd543c63d2a552f141a91781 (diff)
downloadglibc-ce6ba630dbc96f49eb1f30366aa62261df4792f9.tar.gz
glibc-ce6ba630dbc96f49eb1f30366aa62261df4792f9.tar.xz
glibc-ce6ba630dbc96f49eb1f30366aa62261df4792f9.zip
CVE-2018-19591: if_nametoindex: Fix descriptor for overlong name [BZ #23927]
(cherry picked from commit d527c860f5a3f0ed687bd03f0cb464612dc23408)
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/if_index.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index e3d08982d9..782fc5e175 100644
--- a/sysdeps/unix/sysv/linux/if_index.c
+++ b/sysdeps/unix/sysv/linux/if_index.c
@@ -38,11 +38,6 @@ __if_nametoindex (const char *ifname)
   return 0;
 #else
   struct ifreq ifr;
-  int fd = __opensock ();
-
-  if (fd < 0)
-    return 0;
-
   if (strlen (ifname) >= IFNAMSIZ)
     {
       __set_errno (ENODEV);
@@ -50,6 +45,12 @@ __if_nametoindex (const char *ifname)
     }
 
   strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+
+  int fd = __opensock ();
+
+  if (fd < 0)
+    return 0;
+
   if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
     {
       int saved_errno = errno;