[glib] httpproxy: Fix invalid request on invalid hostnames
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] httpproxy: Fix invalid request on invalid hostnames
- Date: Tue, 3 Jan 2017 13:36:49 +0000 (UTC)
commit 5c566e435e48dadde1106c757ab3d18758cdd17c
Author: Bastien Nocera <hadess hadess net>
Date: Wed Dec 7 17:29:35 2016 +0100
httpproxy: Fix invalid request on invalid hostnames
When an invalid hostname is passed for connection, the
g_hostname_to_ascii() might fail when creating the request in
create_request(). Make sure that error is caught and reported rather
than passing "(null)" as the hostname of the site we want to connect to.
https://bugzilla.gnome.org/show_bug.cgi?id=772989
gio/ghttpproxy.c | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/gio/ghttpproxy.c b/gio/ghttpproxy.c
index 18ceb8b..173960d 100644
--- a/gio/ghttpproxy.c
+++ b/gio/ghttpproxy.c
@@ -69,8 +69,9 @@ g_http_proxy_init (GHttpProxy *proxy)
}
static gchar *
-create_request (GProxyAddress *proxy_address,
- gboolean *has_cred)
+create_request (GProxyAddress *proxy_address,
+ gboolean *has_cred,
+ GError **error)
{
const gchar *hostname;
gint port;
@@ -83,13 +84,19 @@ create_request (GProxyAddress *proxy_address,
*has_cred = FALSE;
hostname = g_proxy_address_get_destination_hostname (proxy_address);
+ ascii_hostname = g_hostname_to_ascii (hostname);
+ if (!ascii_hostname)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Invalid hostname"));
+ return NULL;
+ }
port = g_proxy_address_get_destination_port (proxy_address);
username = g_proxy_address_get_username (proxy_address);
password = g_proxy_address_get_password (proxy_address);
request = g_string_new (NULL);
- ascii_hostname = g_hostname_to_ascii (hostname);
g_string_append_printf (request,
"CONNECT %s:%i HTTP/1.0\r\n"
"Host: %s:%i\r\n"
@@ -214,7 +221,9 @@ g_http_proxy_connect (GProxy *proxy,
in = g_io_stream_get_input_stream (io_stream);
out = g_io_stream_get_output_stream (io_stream);
- buffer = create_request (proxy_address, &has_cred);
+ buffer = create_request (proxy_address, &has_cred, error);
+ if (!buffer)
+ goto error;
if (!g_output_stream_write_all (out, buffer, strlen (buffer), NULL,
cancellable, error))
goto error;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]