guri: Correctly set an error when parsing an invalid hostname

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2020-12-04 13:20:06 +00:00
parent 1d461bc9f4
commit 95c19181ae
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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