From 76aa6f8e0defe8811f9bb28d4ec433b833b80d77 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Jun 2016 00:56:13 +0200 Subject: [PATCH] libnm: don't serialize empty hardware address on D-Bus _nm_utils_hwaddr_to_dbus() would serialize invalid hardware addresses as "'cloned-mac-address': <@ay []>". An empty array is treated the same as no hardware address set, so we should not serialize it in the first place. This is a change in behavior on how the connection is exported on D-Bus, but it should not have any bad consequences. We need this as we later want to deprecate the 'cloned-mac-address' D-Bus field and overwrite it via a 'assigned-mac-address' field. In this case, the "<@ay []>" is interfering. While it could be worked around by treating an empty MAC address as "unset", fix it instead and just not serialize it. --- libnm-core/nm-utils.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 21cbe337a1..5c4bfb50b9 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3316,17 +3316,20 @@ nm_utils_hwaddr_matches (gconstpointer hwaddr1, GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value) { - const char *str = g_value_get_string (prop_value); + const char *str; guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; int len; - if (str) { - len = hwaddr_binary_len (str); - g_return_val_if_fail (len > 0 && len <= NM_UTILS_HWADDR_LEN_MAX, NULL); - if (!nm_utils_hwaddr_aton (str, buf, len)) - len = 0; - } else - len = 0; + str = g_value_get_string (prop_value); + if (!str) + return NULL; + + len = _nm_utils_hwaddr_length (str); + if (len == 0) + return NULL; + + if (!nm_utils_hwaddr_aton (str, buf, len)) + return NULL; return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, buf, len, 1); }