[glib/mcatanzaro/#2597: 2/3] simpleproxyresolver: tighten precondition checks on default_proxy




commit 440a93c69cbf486fbd0bd6f3756b005baedb446a
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Thu Jun 9 13:28:02 2022 -0500

    simpleproxyresolver: tighten precondition checks on default_proxy
    
    Currently it's possible to pass nonsense like empty strings or
    gobbledygook for the default proxy. This is programmer error. Enforce it
    with a precondition check. Adjust a couple tests that were violating the
    precondition by passing NULL: the parameter is not NULLable, so you
    can't do that.

 gio/gsimpleproxyresolver.c | 7 +++++++
 gio/tests/simple-proxy.c   | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsimpleproxyresolver.c b/gio/gsimpleproxyresolver.c
index fdeb6c5a44..ba73952dd1 100644
--- a/gio/gsimpleproxyresolver.c
+++ b/gio/gsimpleproxyresolver.c
@@ -536,7 +536,14 @@ void
 g_simple_proxy_resolver_set_default_proxy (GSimpleProxyResolver *resolver,
                                            const gchar          *default_proxy)
 {
+  GError *error = NULL;
+
   g_return_if_fail (G_IS_SIMPLE_PROXY_RESOLVER (resolver));
+  if (!g_uri_is_valid (default_proxy, 0, &error))
+    {
+      g_critical ("%s is not a valid URI: %s", default_proxy, error->message);
+      return;
+    }
 
   g_free (resolver->priv->default_proxy);
   resolver->priv->default_proxy = g_strdup (default_proxy);
diff --git a/gio/tests/simple-proxy.c b/gio/tests/simple-proxy.c
index d696f42f0f..d81f17a5d6 100644
--- a/gio/tests/simple-proxy.c
+++ b/gio/tests/simple-proxy.c
@@ -43,7 +43,7 @@ test_uris (void)
 
   /* Valid URI. */
   uri = "http://%E0%B4%A8%E0%B4%B2:80/";;
-  resolver = g_simple_proxy_resolver_new (NULL, (char **) ignore_hosts);
+  resolver = g_simple_proxy_resolver_new ("direct://", (char **) ignore_hosts);
 
   proxies = g_proxy_resolver_lookup (resolver, uri, NULL, &error);
   g_assert_no_error (error);
@@ -62,7 +62,7 @@ test_uris (void)
   /* Invalid URI. */
   uri = "%E0%B4%A8%E0%B4%B2";
   str = g_strdup_printf ("Invalid URI ā€˜%sā€™", uri);
-  resolver = g_simple_proxy_resolver_new (NULL, (char **) ignore_hosts);
+  resolver = g_simple_proxy_resolver_new ("direct://", (char **) ignore_hosts);
 
   proxies = g_proxy_resolver_lookup (resolver, uri, NULL, &error);
   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]