about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDavid Hill <dhill@conformal.com>2013-06-07 13:23:58 -0400
committerDavid Hill <dhill@conformal.com>2013-06-07 13:23:58 -0400
commit100efa23d892ea219b665c02ffa71e94e1128c0b (patch)
treeb599f4987b85d26a5b3e5fe8bd01523fb44c1a7d
parentdac4f96636759667d483426fed012de344276740 (diff)
downloadxombrero-100efa23d892ea219b665c02ffa71e94e1128c0b.tar.gz
make sure an invalid proxy cannot be used.
-rw-r--r--settings.c68
-rw-r--r--xombrero.c14
-rw-r--r--xombrero.h2
3 files changed, 52 insertions, 32 deletions
diff --git a/settings.c b/settings.c
index 760a2d6..6f9ffdd 100644
--- a/settings.c
+++ b/settings.c
@@ -262,6 +262,7 @@ int		check_gui_mode(char **);
 int		check_history_autosave(char **);
 int		check_home(char **);
 int		check_http_proxy(char **);
+int		check_http_proxy_scheme(const char *);
 int		check_http_proxy_starts_enabled(char **);
 int		check_icon_size(char **);
 int		check_max_connections(char **);
@@ -598,35 +599,16 @@ struct settings		rs[] = {
 int
 set_http_proxy(char *proxy)
 {
-	char *scheme;
+	char *tmpproxy = proxy;
 
 	/* see if we need to clear it */
-	if (proxy == NULL || strlen(proxy) == 0) {
-		setup_proxy(NULL);
-		return (0);
-	}
+	if (proxy == NULL || strlen(proxy) == 0)
+		tmpproxy = NULL;
 
-	scheme = g_uri_parse_scheme(proxy);
-	if (scheme == NULL)
-		return (1);
+	if (check_http_proxy_scheme(proxy) == 0)
+		tmpproxy = NULL;
 
-#if SOUP_CHECK_VERSION(2, 42, 2)
-	if (strcmp(scheme, "socks5") != 0 && strcmp(scheme, "socks4a") != 0 &&
-	    strcmp(scheme, "socks4") != 0 && strcmp(scheme, "socks") != 0 &&
-	    strcmp(scheme, "http") != 0) {
-		free(scheme);
-		return (1);
-	}
-#else
-	if (strcmp(scheme, "http") != 0) {
-		free(scheme);
-		return (1);
-	}
-#endif
-	free(scheme);
-	setup_proxy(proxy);
-
-	return (0);
+	return (setup_proxy(tmpproxy));
 }
 
 int
@@ -637,6 +619,34 @@ check_http_proxy(char **tt)
 }
 
 int
+check_http_proxy_scheme(const char *uri)
+{
+	int rv = 0;
+	char *scheme;
+
+	if (!uri)
+		return (0);
+
+	scheme = g_uri_parse_scheme(uri);
+	if (!scheme)
+		return (0);
+
+#if SOUP_CHECK_VERSION(2, 42, 2)
+	if (strcmp(scheme, "socks5") == 0 || strcmp(scheme, "socks4a") == 0 ||
+	    strcmp(scheme, "socks4") == 0 || strcmp(scheme, "socks") == 0 ||
+	    strcmp(scheme, "http") == 0) {
+		rv = 1;
+	}
+#else
+	if (strcmp(scheme, "http") == 0) {
+		rv = 1;
+	}
+#endif
+	free(scheme);
+	return (rv);
+}
+
+int
 check_http_proxy_starts_enabled(char **tt)
 {
 	*tt = g_strdup("Default: Enabled");
@@ -3055,11 +3065,12 @@ check_fancy_bar(char **tt)
 	return (0);
 }
 
-void
+int
 setup_proxy(char *uri)
 {
 	struct tab		*t;
 
+	printf("setup_proxy: uri: %s, proxy_uri: %p\n", uri, proxy_uri);
 	if (proxy_uri) {
 #if SOUP_CHECK_VERSION(2, 42, 2)
 		g_object_set(session, "proxy-resolver", NULL, (char *)NULL);
@@ -3073,6 +3084,7 @@ setup_proxy(char *uri)
 			if (t->sbe.proxy != NULL)
 				gtk_label_set_text(GTK_LABEL(t->sbe.proxy), "");
 	}
+
 	if (http_proxy) {
 		if (http_proxy != uri) {
 			g_free(http_proxy);
@@ -3080,6 +3092,9 @@ setup_proxy(char *uri)
 		}
 	}
 
+	if (uri && check_http_proxy_scheme(uri) != 1)
+		return (1);
+
 	if (uri) {
 		http_proxy = g_strdup(uri);
 		DNPRINTF(XT_D_CONFIG, "setup_proxy: %s\n", uri);
@@ -3108,6 +3123,7 @@ setup_proxy(char *uri)
 		TAILQ_FOREACH(t, &tabs, entry)
 			button_set_file(t->proxy_toggle, "tordisabled.ico");
 	}
+	return (0);
 }
 
 char *
diff --git a/xombrero.c b/xombrero.c
index 5561778..014321a 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -3121,13 +3121,17 @@ proxy_cmd(struct tab *t, struct karg *args)
 		TAILQ_FOREACH(tt, &tabs, entry)
 			gtk_widget_show(t->proxy_toggle);
 		if (http_proxy) {
-			setup_proxy(NULL);
-			button_set_file(t->proxy_toggle, "tordisabled.ico");
+			if (setup_proxy(NULL) == 0)
+				button_set_file(t->proxy_toggle,
+				    "tordisabled.ico");
 			show_oops(t, "http proxy disabled");
 		} else {
-			setup_proxy(http_proxy_save);
-			button_set_file(t->proxy_toggle, "torenabled.ico");
-			show_oops(t, "http_proxy = %s", http_proxy);
+			if (setup_proxy(http_proxy_save) == 0 && http_proxy) {
+				button_set_file(t->proxy_toggle,
+				    "torenabled.ico");
+				show_oops(t, "http_proxy = %s", http_proxy);
+			} else
+				show_oops(t, "invalid proxy: %s", http_proxy_save);
 		}
 	}
 done:
diff --git a/xombrero.h b/xombrero.h
index 5ce9d65..de74b97 100644
--- a/xombrero.h
+++ b/xombrero.h
@@ -831,7 +831,7 @@ int		set(struct tab *, struct karg *);
 int		xtp_page_rt(struct tab *, struct karg *);
 size_t		get_settings_size(void);
 int		settings_add(char *, char *);
-void		setup_proxy(char *);
+int		setup_proxy(char *);
 int		proxy_cmd(struct tab *, struct karg *);
 int		set_browser_mode(struct settings *, char *);
 int		set_encoding(struct tab *, struct karg *);