From a5eb23deb6956b1839fc28b0ca93324531e50d9b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 8 Feb 2015 04:25:12 +0100 Subject: hurd: Ignore bytes beyond sockaddr length for AF_UNIX --- sysdeps/mach/hurd/bind.c | 8 +++----- sysdeps/mach/hurd/connect.c | 4 +++- sysdeps/mach/hurd/sendmsg.c | 4 +++- sysdeps/mach/hurd/sendto.c | 4 +++- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'sysdeps/mach') diff --git a/sysdeps/mach/hurd/bind.c b/sysdeps/mach/hurd/bind.c index de2d3f45a0..4b09be3635 100644 --- a/sysdeps/mach/hurd/bind.c +++ b/sysdeps/mach/hurd/bind.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include "hurd/hurdsocket.h" /* Give the socket FD the local address ADDR (which is LEN bytes long). */ int @@ -37,13 +37,11 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len) if (addr->sun_family == AF_LOCAL) { + char *name = _hurd_sun_path_dupa (addr, len); /* For the local domain, we must create a node in the filesystem using the ifsock translator and then fetch the address from it. */ file_t dir, node, ifsock; - char name[len - offsetof (struct sockaddr_un, sun_path) + 1], *n; - - strncpy (name, addr->sun_path, sizeof name - 1); - name[sizeof name - 1] = '\0'; /* Make sure */ + char *n; dir = __file_name_split (name, &n); if (dir == MACH_PORT_NULL) diff --git a/sysdeps/mach/hurd/connect.c b/sysdeps/mach/hurd/connect.c index f581c19937..43120eebc8 100644 --- a/sysdeps/mach/hurd/connect.c +++ b/sysdeps/mach/hurd/connect.c @@ -22,6 +22,7 @@ #include #include #include +#include "hurd/hurdsocket.h" /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). For connectionless socket types, just set the default address to send to @@ -36,9 +37,10 @@ __connect (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len) if (addr->sun_family == AF_LOCAL) { + char *name = _hurd_sun_path_dupa (addr, len); /* For the local domain, we must look up the name as a file and talk to it with the ifsock protocol. */ - file_t file = __file_name_lookup (addr->sun_path, 0, 0); + file_t file = __file_name_lookup (name, 0, 0); if (file == MACH_PORT_NULL) return -1; err = __ifsock_getsockaddr (file, &aport); diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c index e375e242ef..34fd09c240 100644 --- a/sysdeps/mach/hurd/sendmsg.c +++ b/sysdeps/mach/hurd/sendmsg.c @@ -24,6 +24,7 @@ #include #include #include +#include "hurd/hurdsocket.h" /* Send a message described MESSAGE on socket FD. Returns the number of bytes sent, or -1 for errors. */ @@ -104,9 +105,10 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags) { if (addr->sun_family == AF_LOCAL) { + char *name = _hurd_sun_path_dupa (addr, addr_len); /* For the local domain, we must look up the name as a file and talk to it with the ifsock protocol. */ - file_t file = __file_name_lookup (addr->sun_path, 0, 0); + file_t file = __file_name_lookup (name, 0, 0); if (file == MACH_PORT_NULL) { if (dealloc) diff --git a/sysdeps/mach/hurd/sendto.c b/sysdeps/mach/hurd/sendto.c index 2b18b04b80..577d28892c 100644 --- a/sysdeps/mach/hurd/sendto.c +++ b/sysdeps/mach/hurd/sendto.c @@ -22,6 +22,7 @@ #include #include #include +#include "hurd/hurdsocket.h" /* Send N bytes of BUF on socket FD to peer at address ADDR (which is ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */ @@ -47,9 +48,10 @@ __sendto (int fd, if (addr->sun_family == AF_LOCAL) { + char *name = _hurd_sun_path_dupa (addr, addr_len); /* For the local domain, we must look up the name as a file and talk to it with the ifsock protocol. */ - file_t file = __file_name_lookup (addr->sun_path, 0, 0); + file_t file = __file_name_lookup (name, 0, 0); if (file == MACH_PORT_NULL) return errno; err_port = __ifsock_getsockaddr (file, aport); -- cgit 1.4.1