From 139d49d603a95982e72709d6d310da88781c08e6 Mon Sep 17 00:00:00 2001 From: corinna Date: Fri, 14 Aug 2009 06:58:44 +0000 Subject: [PATCH] * (fhandler_socket::getsockname): Fix length returned for unbound AF_LOCAL sockets. (fhandler_socket::getpeername): Ditto. * net.cc (socketpair): Don't set sun_path and peer_sun_path to make sure getsockname and getpeername return the correct values for AF_LOCAL sockets. --- winsup/cygwin/ChangeLog | 9 +++++++++ winsup/cygwin/fhandler_socket.cc | 4 ++-- winsup/cygwin/net.cc | 4 ---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d6103c0da0..3e7336c1b6 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2009-08-14 Corinna Vinschen + + * (fhandler_socket::getsockname): Fix length returned for unbound + AF_LOCAL sockets. + (fhandler_socket::getpeername): Ditto. + * net.cc (socketpair): Don't set sun_path and peer_sun_path to + make sure getsockname and getpeername return the correct values + for AF_LOCAL sockets. + 2009-08-13 Corinna Vinschen * fhandler_socket.cc (fhandler_socket::accept): Use sizeof rather diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index f213e5d96c..52d03ed078 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -1209,7 +1209,7 @@ fhandler_socket::getsockname (struct sockaddr *name, int *namelen) if (get_sun_path ()) strncat (sun.sun_path, get_sun_path (), UNIX_PATH_LEN - 1); memcpy (name, &sun, min (*namelen, (int) SUN_LEN (&sun) + 1)); - *namelen = (int) SUN_LEN (&sun) + 1; + *namelen = (int) SUN_LEN (&sun) + (get_sun_path () ? 1 : 0); res = 0; } else @@ -1283,7 +1283,7 @@ fhandler_socket::getpeername (struct sockaddr *name, int *namelen) if (get_peer_sun_path ()) strncat (sun.sun_path, get_peer_sun_path (), UNIX_PATH_LEN - 1); memcpy (name, &sun, min (*namelen, (int) SUN_LEN (&sun) + 1)); - *namelen = (int) SUN_LEN (&sun) + 1; + *namelen = (int) SUN_LEN (&sun) + (get_peer_sun_path () ? 1 : 0); } else { diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 80f869a25e..c766d7d081 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -2866,8 +2866,6 @@ socketpair (int family, int type, int protocol, int *sb) if (sb0 >= 0 && fdsock (sb0, dev, insock)) { - ((fhandler_socket *) sb0)->set_sun_path (""); - ((fhandler_socket *) sb0)->set_peer_sun_path (""); ((fhandler_socket *) sb0)->set_addr_family (family); ((fhandler_socket *) sb0)->set_socket_type (type); ((fhandler_socket *) sb0)->connect_state (connected); @@ -2878,8 +2876,6 @@ socketpair (int family, int type, int protocol, int *sb) if (sb1 >= 0 && fdsock (sb1, dev, outsock)) { - ((fhandler_socket *) sb1)->set_sun_path (""); - ((fhandler_socket *) sb1)->set_peer_sun_path (""); ((fhandler_socket *) sb1)->set_addr_family (family); ((fhandler_socket *) sb1)->set_socket_type (type); ((fhandler_socket *) sb1)->connect_state (connected); -- 2.11.0