Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2002-02-07 18:04:32 +0300
committerCorinna Vinschen <corinna@vinschen.de>2002-02-07 18:04:32 +0300
commit1f64102fa6f67ca0893cc78ee21cfabc20348a72 (patch)
tree7839643dd3ed0530e6838a091266972fc3e66bdc /winsup/cygwin
parent7a149da931e2f0469c518d9a91a3164f91214fb6 (diff)
* net.cc (cygwin_getsockname): Fix handling of NULL sun_path.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog4
-rw-r--r--winsup/cygwin/net.cc17
2 files changed, 15 insertions, 6 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index d555fb0a0..84daf61e3 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,7 @@
+2002-02-07 Corinna Vinschen <corinna@vinschen.de>
+
+ * net.cc (cygwin_getsockname): Fix handling of NULL sun_path.
+
2002-01-29 Corinna Vinschen <corinna@vinschen.de>
* net.cc (getdomainname): Fix registry key for 9x systems, too.
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index ac6fdc95e..a564f44fb 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -1375,12 +1375,17 @@ cygwin_getsockname (int fd, struct sockaddr *addr, int *namelen)
struct sockaddr_un *sun = (struct sockaddr_un *) addr;
memset (sun, 0, *namelen);
sun->sun_family = AF_LOCAL;
- /* According to SUSv2 "If the actual length of the address is greater
- than the length of the supplied sockaddr structure, the stored
- address will be truncated." We play it save here so that the
- path always has a trailing 0 even if it's truncated. */
- strncpy (sun->sun_path, sock->get_sun_path (),
- *namelen - sizeof *sun + sizeof sun->sun_path - 1);
+
+ if (!sock->get_sun_path ())
+ sun->sun_path[0] = '\0';
+ else
+ /* According to SUSv2 "If the actual length of the address is
+ greater than the length of the supplied sockaddr structure, the
+ stored address will be truncated." We play it save here so
+ that the path always has a trailing 0 even if it's truncated. */
+ strncpy (sun->sun_path, sock->get_sun_path (),
+ *namelen - sizeof *sun + sizeof sun->sun_path - 1);
+
*namelen = sizeof *sun - sizeof sun->sun_path
+ strlen (sun->sun_path) + 1;
res = 0;