public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited] hurd: Fix buffer overrun in __if_nametoindex
@ 2018-04-03 16:08 Samuel Thibault
  2018-04-03 19:27 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Thibault @ 2018-04-03 16:08 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

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 36b022cb35..28fa4a5e69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-04-03  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+	* sysdeps/mach/hurd/if_index.c (__if_nametoindex): Always end
+	ifr.fr_name with a NUL caracter.
+
 2018-04-03  Wilco Dijkstra  <wdijkstr@arm.com>
 
 	* 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 d637353d74..7f647b7036 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;
-- 
2.16.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [hurd,commited] hurd: Fix buffer overrun in __if_nametoindex
  2018-04-03 16:08 [hurd,commited] hurd: Fix buffer overrun in __if_nametoindex Samuel Thibault
@ 2018-04-03 19:27 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2018-04-03 19:27 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: libc-alpha

On Tue, 3 Apr 2018, Samuel Thibault wrote:

> 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.

Are you sure this truncation is correct?  The conclusion we reached for 
the Linux version was to check for a too-big length and return an ENODEV 
error in that case, instead.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-03 19:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-03 16:08 [hurd,commited] hurd: Fix buffer overrun in __if_nametoindex Samuel Thibault
2018-04-03 19:27 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).