Validate IP address in proxy server preference

Fixes: https://bugs.launchpad.net/midori/+bug/783044
This commit is contained in:
Christian Dywan 2012-08-28 23:57:57 +02:00
parent 36c3a4925a
commit 0f1f26480d
4 changed files with 20 additions and 1 deletions

View file

@ -1531,6 +1531,8 @@ katze_uri_entry_changed_cb (GtkWidget* entry,
gboolean valid = midori_uri_is_location (uri); gboolean valid = midori_uri_is_location (uri);
if (!valid && g_object_get_data (G_OBJECT (entry), "allow_%s")) if (!valid && g_object_get_data (G_OBJECT (entry), "allow_%s"))
valid = uri && g_str_has_prefix (uri, "%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) #if GTK_CHECK_VERSION (3, 2, 0)
g_object_set_data (G_OBJECT (entry), "invalid", GINT_TO_POINTER (*uri && !valid)); g_object_set_data (G_OBJECT (entry), "invalid", GINT_TO_POINTER (*uri && !valid));

View file

@ -127,6 +127,9 @@ namespace Midori {
we'd have to separate the path from the URI first. */ we'd have to separate the path from the URI first. */
if (uri == null) if (uri == null)
return false; return false;
/* Skip leading user/ password */
if (uri.chr (-1, '@') != null)
return is_ip_address (uri.split ("@")[1]);
/* IPv4 */ /* IPv4 */
if (uri[0].isdigit () && (uri.chr (4, '.') != null)) if (uri[0].isdigit () && (uri.chr (4, '.') != null))
return true; return true;

View file

@ -466,7 +466,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
label = gtk_label_new (_("Hostname")); label = gtk_label_new (_("Hostname"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
INDENTED_ADD (label); INDENTED_ADD (label);
entry = katze_property_proxy (settings, "http-proxy", NULL); entry = katze_property_proxy (settings, "http-proxy", "address");
SPANNED_ADD (entry); SPANNED_ADD (entry);
g_signal_connect (settings, "notify::proxy-type", g_signal_connect (settings, "notify::proxy-type",
G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry); G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry);

View file

@ -253,6 +253,19 @@ magic_uri_fingerprint (void)
g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT); 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 static void
magic_uri_format (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/pseudo", magic_uri_pseudo);
g_test_add_func ("/magic-uri/performance", magic_uri_performance); 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/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/format", magic_uri_format);
g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch); g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch);
g_test_add_func ("/magic-uri/commands", magic_uri_commands); g_test_add_func ("/magic-uri/commands", magic_uri_commands);