[X2Go-Commits] [libx2goclient] 06/06: src/x2goclient-network-ssh.c: implement IPv6 scope ID handling.

git-admin at x2go.org git-admin at x2go.org
Mon Jul 29 12:13:25 CEST 2019


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository libx2goclient.

commit bc2d448bf35ea0c7cb0a447410f224418c43c703
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Mon Jul 29 12:12:08 2019 +0200

    src/x2goclient-network-ssh.c: implement IPv6 scope ID handling.
---
 src/x2goclient-network-ssh.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c
index 47f56bf..c103007 100644
--- a/src/x2goclient-network-ssh.c
+++ b/src/x2goclient-network-ssh.c
@@ -187,7 +187,21 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString *
      * brackets if an additional port is specified, check for that.
      */
     if ('[' == tmp_start[0]) {
-      tmp_end = g_strstr_len (tmp_start, -1, "]");
+      /*
+       * Do *not* use g_strstr{,_len} () to search for the next closing
+       * bracket.
+       *
+       * We'll have to search for the LAST one, i.e., begin at the end of the
+       * string.
+       *
+       * This might sound weird at first, but consider that IPv6 addresses MAY
+       * include an optional scope ID and at least the Linux kernel (and
+       * accompanying userspace tools) are very lenient when it comes to
+       * allowed characters, so a spec like this might well be a valid one:
+       *
+       * [a::b:c:d%[]]$]-]]#]]!![[[]:23
+       */
+      tmp_end = g_strrstr_len (tmp_start, -1, "]");
 
       if (tmp_end) {
         /*
@@ -206,8 +220,6 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString *
     else {
       address = g_string_new_len (tmp_start, work_sockspec->len);
     }
-
-    /* FIXME: parse out scope ID! */
   }
   else {
     /*
@@ -232,8 +244,30 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString *
              is_v4 = FALSE;
     char binary_rep[128] = { 0 };
     if (want_v6) {
-      /* Check for an IPv6 address. */
-      is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep));
+      /*
+       * Check for an IPv6 address.
+       *
+       * Additionally, IPv6 addresses MAY contain a scope ID, which inet_pton ()
+       * can't handle.
+       *
+       * We'll have to filter that out first.
+       */
+      gchar *filter_start = address->str,
+            *filter_end = g_strstr_len (filter_start, -1, "%");
+      GString *filter_work = NULL;
+
+      if (filter_end) {
+        --filter_end;
+        filter_work = g_string_new_len (filter_start, filter_end - filter_start);
+      }
+      else {
+        filter_work = g_string_new (filter_start);
+      }
+
+      is_v6 = (1 == inet_pton (AF_INET6, filter_work->str, &binary_rep));
+
+      g_string_free (filter_work, TRUE);
+      filter_work = NULL;
     }
     else {
       /* Check for an IPv4 address. */

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git


More information about the x2go-commits mailing list