vishalmishra434 / rpms / openssh

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