vishalmishra434 / rpms / openssh

Forked from rpms/openssh 3 months ago
Clone
Jan F. Chadima a3dee6
diff -up openssh-5.5p1/channels.c.x11 openssh-5.5p1/channels.c
Jan F. Chadima 2664a6
--- openssh-5.5p1/channels.c.x11	2010-06-30 15:22:45.000000000 +0200
Jan F. Chadima 2664a6
+++ openssh-5.5p1/channels.c	2010-06-30 15:27:42.000000000 +0200
Jan F. Chadima 2664a6
@@ -3332,7 +3332,7 @@ 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;
Jan F. Chadima 2664a6
@@ -3342,7 +3342,11 @@ connect_local_xsocket_path(const char *p
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. Chadima 2664a6
+	if (len <= 0)
Jan F. Chadima 2664a6
+		return -1;
Jan F. Chadima 2664a6
+	if (len > sizeof addr.sun_path)
Jan F. Chadima 2664a6
+		len = sizeof addr.sun_path;
Jan F. Chadima 2664a6
+	memcpy(addr.sun_path, pathname , len);
Jan F. Chadima 2664a6
 	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0)
Jan F. Chadima 2664a6
 		return sock;
Jan F. Chadima 2664a6
 	close(sock);
Jan F. Chadima 2664a6
@@ -3354,8 +3358,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);
Jan F. Chadima 2664a6
+	int len;
Jan F. Chadima a3dee6
+#ifdef linux
Jan F. Chadima a3dee6
+	int ret;
Jan F. Chadima a3dee6
+#endif
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. Chadima 2664a6
+	return connect_local_xsocket_path(buf + 1, len);
Jan F. Chadima a3dee6
 }
Jan F. Chadima 41a56c
 
Jan F. Chadima 2664a6
 int