File openssh-7.6p1-IPv6_X_forwarding.patch of Package openssh.17031
# HG changeset patch
# Parent f3dcdd10982b603041d4d78027c5996c1f328b46
Correctly parse DISPLAY variable for cases where it contains an IPv6 address
(which should - but not always is - in (square) brackets).
bnc#847710 - https://bugzilla.novell.com/show_bug.cgi?id=847710
Index: openssh-7.6p1/channels.c
===================================================================
--- openssh-7.6p1.orig/channels.c 2019-03-12 14:38:35.816933438 +0100
+++ openssh-7.6p1/channels.c 2019-03-12 14:38:36.592937803 +0100
@@ -4594,7 +4594,7 @@ x11_connect_display(struct ssh *ssh)
* one of the following formats: unix:d[.s], :d[.s], ::d[.s]
*/
if (strncmp(display, "unix:", 5) == 0 ||
- display[0] == ':') {
+ (display[0] == ':' && ((cp - display) < 2)) ) {
/* Connect to the unix domain socket. */
if (sscanf(strrchr(display, ':') + 1, "%u",
&display_number) != 1) {
@@ -4613,9 +4613,10 @@ x11_connect_display(struct ssh *ssh)
/*
* Connect to an inet socket. The DISPLAY value is supposedly
* hostname:d[.s], where hostname may also be numeric IP address.
+ * Note that IPv6 numberic addresses contain colons (e.g. ::1:0)
*/
strlcpy(buf, display, sizeof(buf));
- cp = strchr(buf, ':');
+ cp = strrchr(buf, ':');
if (!cp) {
error("Could not find ':' in DISPLAY: %.100s", display);
return -1;
@@ -4630,6 +4631,14 @@ x11_connect_display(struct ssh *ssh)
display);
return -1;
}
+
+ /* Remove brackets surrounding IPv6 addresses if there are any. */
+ if (buf[0] == '[' && (cp = strchr(buf, ']'))) {
+ *cp = 0;
+ cp = buf + 1;
+ } else {
+ cp = buf;
+ }
/* Look up the host address */
memset(&hints, 0, sizeof(hints));