kentpeacock / rpms / openssh

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