bmh10 / rpms / openssh

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