Blame SOURCES/0013-spice-uri-Add-ipv6-support.patch

07d9f9
From e25a335f18c8138fd64e762d24afb512ca13583f Mon Sep 17 00:00:00 2001
07d9f9
From: Pavel Grunt <pgrunt@redhat.com>
07d9f9
Date: Wed, 1 Jun 2016 10:04:49 +0200
07d9f9
Subject: [PATCH 13/15] spice-uri: Add ipv6 support
07d9f9
07d9f9
Just basic support -  http://user:password@[host]:port
07d9f9
07d9f9
Resolves: rhbz#1335239
07d9f9
(cherry picked from commit b542dfa2d58cd352dc596318a1e50f074865ef5e)
07d9f9
---
07d9f9
 src/spice-uri.c | 24 ++++++++++++++++++++----
07d9f9
 tests/uri.c     | 33 +++++++++++++++++++++++++++++++++
07d9f9
 2 files changed, 53 insertions(+), 4 deletions(-)
07d9f9
07d9f9
diff --git a/src/spice-uri.c b/src/spice-uri.c
07d9f9
index c452db3..99431d0 100644
07d9f9
--- a/src/spice-uri.c
07d9f9
+++ b/src/spice-uri.c
07d9f9
@@ -132,8 +132,26 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
07d9f9
         uri = next;
07d9f9
     }
07d9f9
 
07d9f9
-    /* max 2 parts, host:port */
07d9f9
-    uriv = g_strsplit(uri, ":", 2);
07d9f9
+    if (*uri == '[') { /* ipv6 address */
07d9f9
+        uriv = g_strsplit(uri + 1, "]", 2);
07d9f9
+        if (uriv[1] == NULL) {
07d9f9
+            g_set_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
07d9f9
+                        "Missing ']' in ipv6 uri");
07d9f9
+            goto end;
07d9f9
+        }
07d9f9
+        if (*uriv[1] == ':') {
07d9f9
+            uri_port = uriv[1] + 1;
07d9f9
+        } else if (strlen(uriv[1]) > 0) { /* invalid string after the hostname */
07d9f9
+            g_set_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
07d9f9
+                        "Invalid uri address");
07d9f9
+            goto end;
07d9f9
+        }
07d9f9
+    } else {
07d9f9
+        /* max 2 parts, host:port */
07d9f9
+        uriv = g_strsplit(uri, ":", 2);
07d9f9
+        if (uriv[0] != NULL)
07d9f9
+            uri_port = uriv[1];
07d9f9
+    }
07d9f9
 
07d9f9
     if (uriv[0] == NULL || strlen(uriv[0]) == 0) {
07d9f9
         g_set_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
07d9f9
@@ -142,8 +160,6 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
07d9f9
     }
07d9f9
 
07d9f9
     spice_uri_set_hostname(self, uriv[0]);
07d9f9
-    if (uriv[0] != NULL)
07d9f9
-        uri_port = uriv[1];
07d9f9
 
07d9f9
     if (uri_port != NULL) {
07d9f9
         gchar *endptr;
07d9f9
diff --git a/tests/uri.c b/tests/uri.c
07d9f9
index 80b00f4..ea8b794 100644
07d9f9
--- a/tests/uri.c
07d9f9
+++ b/tests/uri.c
07d9f9
@@ -99,12 +99,45 @@ static void test_spice_uri_ipv4_good(void)
07d9f9
     test_spice_uri_good(valid_test_cases, G_N_ELEMENTS(valid_test_cases));
07d9f9
 }
07d9f9
 
07d9f9
+static void test_spice_uri_ipv6_bad(void)
07d9f9
+{
07d9f9
+    const struct test_case invalid_test_cases[] = {
07d9f9
+        {"http://[]:80", "http", NULL, 80, NULL, NULL, "Invalid hostname in uri address"},
07d9f9
+        {"http://[::1", "http", NULL, 3128, NULL, NULL, "Missing ']' in ipv6 uri"},
07d9f9
+        {"http://[host]1234", "http", "host", 3128, NULL, NULL, "Invalid uri address"},
07d9f9
+        {"http://[host]foo/", "http", "host", 3128, NULL, NULL, "Invalid uri address"},
07d9f9
+        {"http://[::1]:port", "http", "::1", 3128, NULL, NULL, "Invalid uri port: port"},
07d9f9
+        {"http://[::127.0.0.1]:", "http", "::127.0.0.1", 3128, NULL, NULL, "Missing uri port"},
07d9f9
+        {"http://[::127.0.0.1]:-42", "http", "::127.0.0.1", 3128, NULL, NULL, "Port out of range"},
07d9f9
+        {"[3ffe:2a00:100:7031::1]:42000000", "http", "3ffe:2a00:100:7031::1", 3128, NULL, NULL, "Port out of range"},
07d9f9
+        {"scheme://[3ffe::192.168.1.1]:3128", "http", "3ffe::192.168.1.1", 3128, NULL, NULL,
07d9f9
+         "Invalid uri scheme for proxy: scheme"},
07d9f9
+    };
07d9f9
+
07d9f9
+    test_spice_uri_bad(invalid_test_cases, G_N_ELEMENTS(invalid_test_cases));
07d9f9
+}
07d9f9
+
07d9f9
+static void test_spice_uri_ipv6_good(void)
07d9f9
+{
07d9f9
+    const struct test_case valid_test_cases[] = {
07d9f9
+        {"http://user:password@[host]:80/", "http", "host", 80, "user", "password", NULL},
07d9f9
+        {"http://user@[1080:0:0:0:8:800:200C:4171]:100", "http", "1080:0:0:0:8:800:200C:4171", 100,
07d9f9
+         "user", NULL, NULL},
07d9f9
+        {"https://[1080::8:800:200C:417A]", "https", "1080::8:800:200C:417A", 3129, NULL, NULL, NULL},
07d9f9
+        {"[3ffe:2a00:100:7031::1]", "http", "3ffe:2a00:100:7031::1", 3128, NULL, NULL, NULL},
07d9f9
+    };
07d9f9
+
07d9f9
+    test_spice_uri_good(valid_test_cases, G_N_ELEMENTS(valid_test_cases));
07d9f9
+}
07d9f9
+
07d9f9
 int main(int argc, char* argv[])
07d9f9
 {
07d9f9
     g_test_init(&argc, &argv, NULL);
07d9f9
 
07d9f9
     g_test_add_func("/spice_uri/ipv4/bad-uri", test_spice_uri_ipv4_bad);
07d9f9
     g_test_add_func("/spice_uri/ipv4/good-uri", test_spice_uri_ipv4_good);
07d9f9
+    g_test_add_func("/spice_uri/ipv6/bad-uri", test_spice_uri_ipv6_bad);
07d9f9
+    g_test_add_func("/spice_uri/ipv6/good-uri", test_spice_uri_ipv6_good);
07d9f9
 
07d9f9
     return g_test_run();
07d9f9
 }
07d9f9
-- 
07d9f9
2.5.5
07d9f9