rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
8f2528
diff -up openssh-5.3p1/channels.c.bz595935 openssh-5.3p1/channels.c
8f2528
--- openssh-5.3p1/channels.c.bz595935	2010-08-12 14:19:28.000000000 +0200
8f2528
+++ openssh-5.3p1/channels.c	2010-08-12 14:33:51.000000000 +0200
8f2528
@@ -3990,21 +3990,24 @@ x11_create_display_inet(int x11_display_
8f2528
 }
8f2528
 
8f2528
 static int
8f2528
-connect_local_xsocket_path(const char *pathname)
8f2528
+connect_local_xsocket_path(const char *pathname, int len)
8f2528
 {
8f2528
 	int sock;
8f2528
 	struct sockaddr_un addr;
8f2528
 
8f2528
+	if (len <= 0)
8f2528
+		return -1;
8f2528
 	sock = socket(AF_UNIX, SOCK_STREAM, 0);
8f2528
 	if (sock < 0)
8f2528
 		error("socket: %.100s", strerror(errno));
8f2528
 	memset(&addr, 0, sizeof(addr));
8f2528
 	addr.sun_family = AF_UNIX;
8f2528
-	strlcpy(addr.sun_path, pathname, sizeof addr.sun_path);
8f2528
-	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0)
8f2528
+	if (len > sizeof addr.sun_path)
8f2528
+		len = sizeof addr.sun_path;
8f2528
+	memcpy(addr.sun_path, pathname, len);
8f2528
+	if (connect(sock, (struct sockaddr *)&addr, sizeof addr - (sizeof addr.sun_path - len) ) == 0)
8f2528
 		return sock;
8f2528
 	close(sock);
8f2528
-	error("connect %.100s: %.100s", addr.sun_path, strerror(errno));
8f2528
 	return -1;
8f2528
 }
8f2528
 
8f2528
@@ -3207,8 +3210,18 @@ static int
8f2528
 connect_local_xsocket(u_int dnr)
8f2528
 {
8f2528
 	char buf[1024];
8f2528
-	snprintf(buf, sizeof buf, _PATH_UNIX_X, dnr);
8f2528
-	return connect_local_xsocket_path(buf);
8f2528
+	int len, ret;
8f2528
+	len = snprintf(buf + 1, sizeof (buf) - 1, _PATH_UNIX_X, dnr);
8f2528
+#ifdef linux
8f2528
+	/* try abstract socket first */
8f2528
+	buf[0] = '\0';
8f2528
+	if ((ret = connect_local_xsocket_path(buf, len + 1)) >= 0)
8f2528
+		return ret;
8f2528
+#endif
8f2528
+	if ((ret = connect_local_xsocket_path(buf + 1, len)) >= 0)
8f2528
+		return ret;
8f2528
+	error("connect %.100s: %.100s", buf + 1, strerror(errno));
8f2528
+	return -1;
8f2528
 }
8f2528
 
8f2528
 int