From 442b7ce899df1c0adbbf51bef40dd09b0fd70a51 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 7 Dec 2016 17:44:08 +0100 Subject: [PATCH] resolver: Return error looking up invalid hostnames Make g_resolver_lookup_by_name() and g_resolver_lookup_by_name_async() error out when invalid hostnames are passed. https://bugzilla.gnome.org/show_bug.cgi?id=772989 --- gio/gresolver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gio/gresolver.c b/gio/gresolver.c index 3b4e6c417..3b4f174b3 100644 --- a/gio/gresolver.c +++ b/gio/gresolver.c @@ -403,6 +403,13 @@ g_resolver_lookup_by_name (GResolver *resolver, if (g_hostname_is_non_ascii (hostname)) hostname = ascii_hostname = g_hostname_to_ascii (hostname); + if (!hostname) + { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, + _("Invalid hostname")); + return NULL; + } + g_resolver_maybe_reload (resolver); addrs = G_RESOLVER_GET_CLASS (resolver)-> lookup_by_name (resolver, hostname, cancellable, error); @@ -460,6 +467,19 @@ g_resolver_lookup_by_name_async (GResolver *resolver, if (g_hostname_is_non_ascii (hostname)) hostname = ascii_hostname = g_hostname_to_ascii (hostname); + if (!hostname) + { + GTask *task; + + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, + _("Invalid hostname")); + task = g_task_new (resolver, cancellable, callback, user_data); + g_task_set_source_tag (task, g_resolver_lookup_by_name_async); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + g_resolver_maybe_reload (resolver); G_RESOLVER_GET_CLASS (resolver)-> lookup_by_name_async (resolver, hostname, cancellable, callback, user_data);