rcolebaugh / rpms / openssh

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