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