From: Christian Dywan Date: Tue, 28 Aug 2012 21:57:57 +0000 (+0200) Subject: Validate IP address in proxy server preference X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f1f26480dda3168173d87f581e4992d97dc0a96;p=midori Validate IP address in proxy server preference Fixes: https://bugs.launchpad.net/midori/+bug/783044 --- diff --git a/katze/katze-utils.c b/katze/katze-utils.c index 1433f434..b082c3ee 100644 --- a/katze/katze-utils.c +++ b/katze/katze-utils.c @@ -1531,6 +1531,8 @@ katze_uri_entry_changed_cb (GtkWidget* entry, gboolean valid = midori_uri_is_location (uri); if (!valid && g_object_get_data (G_OBJECT (entry), "allow_%s")) valid = uri && g_str_has_prefix (uri, "%s"); + if (!valid) + valid = midori_uri_is_ip_address (uri); #if GTK_CHECK_VERSION (3, 2, 0) g_object_set_data (G_OBJECT (entry), "invalid", GINT_TO_POINTER (*uri && !valid)); diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala index c823a48f..5a8fab3e 100644 --- a/katze/midori-uri.vala +++ b/katze/midori-uri.vala @@ -127,6 +127,9 @@ namespace Midori { we'd have to separate the path from the URI first. */ if (uri == null) return false; + /* Skip leading user/ password */ + if (uri.chr (-1, '@') != null) + return is_ip_address (uri.split ("@")[1]); /* IPv4 */ if (uri[0].isdigit () && (uri.chr (4, '.') != null)) return true; diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c index f685c581..f00a7998 100644 --- a/midori/midori-preferences.c +++ b/midori/midori-preferences.c @@ -466,7 +466,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences, label = gtk_label_new (_("Hostname")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); INDENTED_ADD (label); - entry = katze_property_proxy (settings, "http-proxy", NULL); + entry = katze_property_proxy (settings, "http-proxy", "address"); SPANNED_ADD (entry); g_signal_connect (settings, "notify::proxy-type", G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry); diff --git a/tests/magic-uri.c b/tests/magic-uri.c index 53bee470..826307fd 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -253,6 +253,19 @@ magic_uri_fingerprint (void) g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT); } +static void +magic_uri_ip (void) +{ + g_assert (midori_uri_is_ip_address ("192.168.1.1")); + g_assert (midori_uri_is_ip_address ("192.168.1.1:1234")); + g_assert (midori_uri_is_ip_address ("user@192.168.1.1")); + g_assert (midori_uri_is_ip_address ("user:password@192.168.1.1")); + g_assert (midori_uri_is_ip_address ("2001:0db8:85a3:0000:0000:8a2e:0370:7334")); + g_assert (midori_uri_is_ip_address ("fe80:0:0:0:202:b3ff:fe1e:8329")); + g_assert (midori_uri_is_ip_address ("fe80::202:b3ff:fe1e:8329")); + g_assert (midori_uri_is_ip_address ("fe80::76e5:bff:fe04:38e0/64")); +} + static void magic_uri_format (void) { @@ -357,6 +370,7 @@ main (int argc, g_test_add_func ("/magic-uri/pseudo", magic_uri_pseudo); g_test_add_func ("/magic-uri/performance", magic_uri_performance); g_test_add_func ("/magic-uri/fingerprint", magic_uri_fingerprint); + g_test_add_func ("/magic-uri/ip", magic_uri_ip); g_test_add_func ("/magic-uri/format", magic_uri_format); g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch); g_test_add_func ("/magic-uri/commands", magic_uri_commands);