summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/if_index.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/if_index.c')
-rw-r--r--sysdeps/unix/sysv/linux/if_index.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index 7c3bb6cb04..e3d08982d9 100644
--- a/sysdeps/unix/sysv/linux/if_index.c
+++ b/sysdeps/unix/sysv/linux/if_index.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -43,16 +43,22 @@ __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)
{
int saved_errno = errno;
- close_not_cancel_no_status (fd);
+ __close_nocancel_nostatus (fd);
if (saved_errno == EINVAL)
__set_errno (ENOSYS);
return 0;
}
- close_not_cancel_no_status (fd);
+ __close_nocancel_nostatus (fd);
return ifr.ifr_ifindex;
#endif
}
@@ -224,7 +230,7 @@ __if_indextoname (unsigned int ifindex, char *ifname)
ifr.ifr_ifindex = ifindex;
status = __ioctl (fd, SIOCGIFNAME, &ifr);
- close_not_cancel_no_status (fd);
+ __close_nocancel_nostatus (fd);
if (status < 0)
{