From 6f94b16507642ed72e03cf56bc69b0ad87a6d7ec Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Oct 2017 13:25:54 +0200 Subject: [PATCH] libnm: fix nm_connection_diff() for settings without properties NMSettingGeneric has no properties at all. Hence, nm_connection_diff() would report that a connection A with a generic setting and a connection B without a generic setting are equal. They are not. For empty settings, let nm_setting_diff() return also empty difference hash. --- libnm-core/nm-setting.c | 10 ++++++++++ src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 3e2ee3debc..b420601f9c 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1322,6 +1322,7 @@ nm_setting_diff (NMSetting *a, NMSettingDiffResult a_result_default = NM_SETTING_DIFF_RESULT_IN_A_DEFAULT; NMSettingDiffResult b_result_default = NM_SETTING_DIFF_RESULT_IN_B_DEFAULT; gboolean results_created = FALSE; + gboolean compared_any = FALSE; g_return_val_if_fail (results != NULL, FALSE); g_return_val_if_fail (NM_IS_SETTING (a), FALSE); @@ -1370,6 +1371,8 @@ nm_setting_diff (NMSetting *a, if (strcmp (prop_spec->name, NM_SETTING_NAME) == 0) continue; + compared_any = TRUE; + if (b) { gboolean different; @@ -1427,6 +1430,13 @@ nm_setting_diff (NMSetting *a, } g_free (property_specs); + if (!compared_any && !b) { + /* special case: the setting has no properties, and the opposite + * setting @b is not given. The settings differ, and we signal that + * by returning an empty results hash. */ + return FALSE; + } + /* Don't return an empty hash table */ if (results_created && !g_hash_table_size (*results)) { g_hash_table_destroy (*results); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 5d4c43b4be..2178201af8 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -4309,8 +4309,10 @@ test_write_wired_static_with_generic (void) { gs_unref_hashtable GHashTable *diffs = NULL; - g_assert (nm_connection_diff (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT, &diffs)); - g_assert (!diffs); + g_assert (!nm_connection_diff (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT, &diffs)); + g_assert (diffs); + g_assert (g_hash_table_size (diffs) == 1); + g_assert (g_hash_table_lookup (diffs, "generic")); g_assert (!nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); } g_assert (!nm_connection_get_setting (reread, NM_TYPE_SETTING_GENERIC));