rcolebaugh / rpms / openssh

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