From 667e3edfbd62d4b2f9ceb90eaaf38571441eaf36 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 12 Dec 2011 17:54:14 +0100 Subject: [PATCH] bearer: ensure only valid bearers are exported We setup bearer export in DBus only if the input properties are the expected ones. --- src/mm-bearer.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/mm-bearer.c b/src/mm-bearer.c index 01afd3b3..c5a73f6f 100644 --- a/src/mm-bearer.c +++ b/src/mm-bearer.c @@ -235,14 +235,10 @@ mm_bearer_new (MMBaseModem *modem, /* Ensure only one capability is set */ g_assert_cmpuint (mm_count_bits_set (capability), ==, 1); - /* Build the unique path for the Bearer, and create the object */ - path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "%d", id++); + /* Create the object */ bearer = g_object_new (MM_TYPE_BEARER, - MM_BEARER_PATH, path, - MM_BEARER_MODEM, modem, MM_BEARER_CAPABILITY, capability, NULL); - g_free (path); /* Parse and set input properties */ if (!parse_input_properties (bearer, capability, properties, error)) { @@ -257,6 +253,15 @@ mm_bearer_new (MMBaseModem *modem, mm_gdbus_bearer_set_ip4_config (MM_GDBUS_BEARER (bearer), NULL); mm_gdbus_bearer_set_ip6_config (MM_GDBUS_BEARER (bearer), NULL); + /* Set modem and path ONLY after having checked input properties, so that + * we don't export invalid bearers. */ + path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "%d", id++); + g_object_set (bearer, + MM_BEARER_PATH, path, + MM_BEARER_MODEM, modem, + NULL); + g_free (path); + return bearer; } @@ -433,7 +438,7 @@ mm_bearer_class_init (MMBearerClass *klass) "Path", "DBus path of the Bearer", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_PATH, properties[PROP_PATH]); properties[PROP_MODEM] =