f28682
diff -up openssh-7.2p2/channels.c.x11 openssh-7.2p2/channels.c
f28682
--- openssh-7.2p2/channels.c.x11	2016-03-09 19:04:48.000000000 +0100
f28682
+++ openssh-7.2p2/channels.c	2016-06-03 10:42:04.775164520 +0200
f28682
@@ -3990,21 +3990,24 @@ x11_create_display_inet(int x11_display_
2664a6
 }
2664a6
 
2664a6
 static int
2664a6
-connect_local_xsocket_path(const char *pathname)
2664a6
+connect_local_xsocket_path(const char *pathname, int len)
2664a6
 {
2664a6
 	int sock;
2664a6
 	struct sockaddr_un addr;
f28682
 
f28682
+	if (len <= 0)
f28682
+		return -1;
f28682
 	sock = socket(AF_UNIX, SOCK_STREAM, 0);
f28682
 	if (sock < 0)
2664a6
 		error("socket: %.100s", strerror(errno));
2664a6
 	memset(&addr, 0, sizeof(addr));
2664a6
 	addr.sun_family = AF_UNIX;
2664a6
-	strlcpy(addr.sun_path, pathname, sizeof addr.sun_path);
Jan F 5daee1
-	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0)
2664a6
+	if (len > sizeof addr.sun_path)
2664a6
+		len = sizeof addr.sun_path;
Jan F 5daee1
+	memcpy(addr.sun_path, pathname, len);
Jan F 5daee1
+	if (connect(sock, (struct sockaddr *)&addr, sizeof addr - (sizeof addr.sun_path - len) ) == 0)
2664a6
 		return sock;
2664a6
 	close(sock);
Jan F 5daee1
-	error("connect %.100s: %.100s", addr.sun_path, strerror(errno));
Jan F 5daee1
 	return -1;
Jan F 5daee1
 }
Jan F 5daee1
 
f28682
@@ -4012,8 +4015,18 @@ static int
a3dee6
 connect_local_xsocket(u_int dnr)
a3dee6
 {
a3dee6
 	char buf[1024];
2664a6
-	snprintf(buf, sizeof buf, _PATH_UNIX_X, dnr);
2664a6
-	return connect_local_xsocket_path(buf);
86f29c
+	int len, ret;
2664a6
+	len = snprintf(buf + 1, sizeof (buf) - 1, _PATH_UNIX_X, dnr);
a3dee6
+#ifdef linux
a3dee6
+	/* try abstract socket first */
a3dee6
+	buf[0] = '\0';
2664a6
+	if ((ret = connect_local_xsocket_path(buf, len + 1)) >= 0)
a3dee6
+		return ret;
a3dee6
+#endif
Jan F 5daee1
+	if ((ret = connect_local_xsocket_path(buf + 1, len)) >= 0)
Jan F 5daee1
+		return ret;
Jan F 5daee1
+	error("connect %.100s: %.100s", buf + 1, strerror(errno));
Jan F 5daee1
+	return -1;
a3dee6
 }
41a56c
 
2664a6
 int