[glib: 4/5] guri: Correctly set an error when parsing an invalid hostname




commit 95c19181aec19403ec84de85a77dc1be94ae4089
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Dec 4 13:20:06 2020 +0000

    guri: Correctly set an error when parsing an invalid hostname
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 glib/guri.c      | 16 ++++++++++++++--
 glib/tests/uri.c |  4 ++++
 2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index 19fe4ac71..571cf10aa 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -604,9 +604,21 @@ parse_host (const gchar  *start,
     }
 
   if (g_hostname_is_non_ascii (decoded))
-    host = g_hostname_to_ascii (decoded);
+    {
+      host = g_hostname_to_ascii (decoded);
+      if (host == NULL)
+        {
+          g_free (decoded);
+          g_set_error (error, G_URI_ERROR, G_URI_ERROR_BAD_HOST,
+                       _("Illegal internationalized hostname ‘%.*s’ in URI"),
+                       (gint) length, start);
+          return FALSE;
+        }
+    }
   else
-    host = g_steal_pointer (&decoded);
+    {
+      host = g_steal_pointer (&decoded);
+    }
 
  ok:
   if (out)
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index 72698b73c..2c610382b 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -758,6 +758,10 @@ static const UriAbsoluteTest absolute_tests[] = {
     { NULL, NULL, NULL, -1, NULL, NULL, NULL } },
   { "http://[fe80::dead:beef%25em1%00]/";, G_URI_FLAGS_NONE, FALSE, G_URI_ERROR_BAD_HOST,
     { NULL, NULL, NULL, -1, NULL, NULL, NULL } },
+
+  /* Invalid IDN hostname */
+  { "http://xn--mixed-\xc3\xbcp/";, G_URI_FLAGS_NONE, FALSE, G_URI_ERROR_BAD_HOST,
+    { NULL, NULL, NULL, -1, NULL, NULL, NULL } },
 };
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]