openssh/openssh-7.2p2-x11.patch

56 lines
1.5 KiB
Diff
Raw Normal View History

diff --git a/channels.c b/channels.c
--- a/channels.c (revision 8241b9c0529228b4b86d88b1a6076fb9f97e4a99)
+++ b/channels.c (date 1703026069921)
@@ -5075,11 +5075,13 @@
2010-06-30 14:45:30 +00:00
}
2010-06-30 14:45:30 +00:00
static int
-connect_local_xsocket_path(const char *pathname)
+connect_local_xsocket_path(const char *pathname, int len)
{
int sock;
struct sockaddr_un addr;
+ if (len <= 0)
+ return -1;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == -1) {
2010-06-30 14:45:30 +00:00
error("socket: %.100s", strerror(errno));
@@ -5087,11 +5089,12 @@
}
2010-06-30 14:45:30 +00:00
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- strlcpy(addr.sun_path, pathname, sizeof addr.sun_path);
- if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0)
2010-06-30 14:45:30 +00:00
+ if (len > sizeof addr.sun_path)
+ len = sizeof addr.sun_path;
+ memcpy(addr.sun_path, pathname, len);
+ if (connect(sock, (struct sockaddr *)&addr, sizeof addr - (sizeof addr.sun_path - len) ) == 0)
2010-06-30 14:45:30 +00:00
return sock;
close(sock);
- error("connect %.100s: %.100s", addr.sun_path, strerror(errno));
return -1;
}
@@ -5099,8 +5102,18 @@
2010-06-25 12:08:42 +00:00
connect_local_xsocket(u_int dnr)
{
char buf[1024];
2010-06-30 14:45:30 +00:00
- snprintf(buf, sizeof buf, _PATH_UNIX_X, dnr);
- return connect_local_xsocket_path(buf);
2014-07-03 14:42:56 +00:00
+ int len, ret;
2010-06-30 14:45:30 +00:00
+ len = snprintf(buf + 1, sizeof (buf) - 1, _PATH_UNIX_X, dnr);
2010-06-25 12:08:42 +00:00
+#ifdef linux
+ /* try abstract socket first */
+ buf[0] = '\0';
2010-06-30 14:45:30 +00:00
+ if ((ret = connect_local_xsocket_path(buf, len + 1)) >= 0)
2010-06-25 12:08:42 +00:00
+ return ret;
+#endif
+ if ((ret = connect_local_xsocket_path(buf + 1, len)) >= 0)
+ return ret;
+ error("connect %.100s: %.100s", buf + 1, strerror(errno));
+ return -1;
2010-06-25 12:08:42 +00:00
}
2017-03-20 14:55:43 +00:00
#ifdef __APPLE__