From ae67198d55bf5bab903eb01d049f15d7a35c38ba Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 5 Mar 2018 18:08:47 +0100 Subject: [PATCH] Cygwin: move sun_name_t constructors into fhandler_socket_unix.cc They are only used there anyway and it allows to use the AF_UNIX macro without tweaking header files. While at it, improve both constructors. The default constructor now creates the name of an unnamed socket, the constructor taking parameters carefully checks its input. Signed-off-by: Corinna Vinschen --- winsup/cygwin/fhandler.h | 14 ++------------ winsup/cygwin/fhandler_socket_unix.cc | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index e9a247256..da600f2dc 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -842,18 +842,8 @@ class sun_name_t /* Allows 108 bytes sun_path plus trailing NUL */ char _nul[sizeof (struct sockaddr_un) + 1]; }; - sun_name_t () - { - un_len = 0; - un.sun_family = 0; - _nul[sizeof (struct sockaddr_un)] = '\0'; - } - sun_name_t (const struct sockaddr *name, __socklen_t namelen) - { - un_len = namelen < (__socklen_t) sizeof un ? namelen : sizeof un; - memcpy (&un, name, un_len); - _nul[sizeof (struct sockaddr_un)] = '\0'; - } + sun_name_t (); + sun_name_t (const struct sockaddr *name, __socklen_t namelen); void *operator new (size_t) __attribute__ ((nothrow)) { return cmalloc_abort (HEAP_FHANDLER, sizeof (sun_name_t)); } diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc index 36a3cb3c4..f93b91221 100644 --- a/winsup/cygwin/fhandler_socket_unix.cc +++ b/winsup/cygwin/fhandler_socket_unix.cc @@ -69,6 +69,23 @@ GUID __cygwin_socket_guid = { .Data4 = { 0xba, 0xb3, 0xc5, 0xb1, 0xf9, 0x2c, 0xb8, 0x8c } }; +sun_name_t::sun_name_t () +{ + un_len = sizeof (sa_family_t); + un.sun_family = AF_UNIX; + _nul[sizeof (struct sockaddr_un)] = '\0'; +} + +sun_name_t::sun_name_t (const struct sockaddr *name, socklen_t namelen) +{ + if (namelen < 0) + namelen = 0; + un_len = namelen < (__socklen_t) sizeof un ? namelen : sizeof un; + if (name) + memcpy (&un, name, un_len); + _nul[sizeof (struct sockaddr_un)] = '\0'; +} + HANDLE fhandler_socket_unix::create_abstract_link (const sun_name_t *sun, PUNICODE_STRING pipe_name)