From 511ed56f2e792bea5e7145e1d5d5c93b9f47c41f Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 3 Apr 2018 18:06:15 +0200 Subject: hurd: Fix buffer overrun in __if_nametoindex and building with mainline GCC which reports it. * sysdeps/mach/hurd/if_index.c (__if_nametoindex): Always end ifr.fr_name with a NUL caracter. --- ChangeLog | 5 +++++ sysdeps/mach/hurd/if_index.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 36b022c..28fa4a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-04-03 Samuel Thibault + + * sysdeps/mach/hurd/if_index.c (__if_nametoindex): Always end + ifr.fr_name with a NUL caracter. + 2018-04-03 Wilco Dijkstra * sysdeps/ieee754/dbl-64/s_sin.c (__sin): Cleanup ifdefs. diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c index d637353..7f647b7 100644 --- a/sysdeps/mach/hurd/if_index.c +++ b/sysdeps/mach/hurd/if_index.c @@ -37,7 +37,9 @@ __if_nametoindex (const char *ifname) if (fd < 0) return 0; - strncpy (ifr.ifr_name, ifname, IFNAMSIZ); + strncpy (ifr.ifr_name, ifname, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMESIZ - 1] = '\0'; + if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0) { int saved_errno = errno; -- cgit v1.1