From d047ca341b3ae077dcaf3d3fa9a6118528be227c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 6 Aug 2018 15:46:56 +0200 Subject: [PATCH] portal network monitor: Validate connectivity Only accept connectivity values that are actually in the range of GNetworkConnectivity. https://gitlab.gnome.org/GNOME/glib/merge_requests/227 --- gio/gnetworkmonitorportal.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/gio/gnetworkmonitorportal.c b/gio/gnetworkmonitorportal.c index 77fd46654..3c4c2f696 100644 --- a/gio/gnetworkmonitorportal.c +++ b/gio/gnetworkmonitorportal.c @@ -92,6 +92,20 @@ g_network_monitor_portal_get_property (GObject *object, } } +static gboolean +is_valid_connectivity (guint32 value) +{ + GEnumValue *enum_value; + GEnumClass *enum_klass; + + enum_klass = g_type_class_ref (G_TYPE_NETWORK_CONNECTIVITY); + enum_value = g_enum_get_value (enum_klass, value); + + g_type_class_unref (enum_klass); + + return enum_value != NULL; +} + static void got_available (GObject *source, GAsyncResult *res, @@ -228,7 +242,8 @@ got_connectivity (GObject *source, g_variant_unref (ret); } - if (nm->priv->connectivity != connectivity) + if (nm->priv->connectivity != connectivity && + is_valid_connectivity (connectivity)) { nm->priv->connectivity = connectivity; g_object_notify (G_OBJECT (nm), "connectivity"); @@ -292,7 +307,8 @@ got_status (GObject *source, should_emit_changed = TRUE; } - if (nm->priv->connectivity != connectivity) + if (nm->priv->connectivity != connectivity && + is_valid_connectivity (connectivity)) { nm->priv->connectivity = connectivity; g_object_notify (G_OBJECT (nm), "connectivity"); @@ -361,7 +377,8 @@ proxy_properties_changed (GDBusProxy *proxy, if (ret) { GNetworkConnectivity connectivity = g_variant_get_uint32 (ret); - if (nm->priv->connectivity != connectivity) + if (nm->priv->connectivity != connectivity && + is_valid_connectivity (connectivity)) { nm->priv->connectivity = connectivity; g_object_notify (G_OBJECT (nm), "connectivity");