vishalmishra434 / rpms / openssh

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