libnm: make NMSettingOvsExternalIDs.verify() deterministic

Iterating over a hash table is not deterministic. When we have
two invalid keys in ovs-external-ids, we should deterministically
get the same error message.

Instead, iterate over the (sorted) keys. This does have an overhead,
because we need to fetch the keys, and we need to lookup each value
by key. Still, correctness and determinism is more important.
This commit is contained in:
Thomas Haller
2023-01-09 22:33:28 +01:00
parent 4c2db6a3fd
commit 96d01a5f8b

View File

@@ -293,12 +293,16 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
if (priv->data) { if (priv->data) {
gs_free_error GError *local = NULL; gs_free_error GError *local = NULL;
GHashTableIter iter; const char *const *keys;
const char *key; guint len;
const char *val; guint i;
keys = nm_setting_ovs_external_ids_get_data_keys(self, &len);
for (i = 0; i < len; i++) {
const char *key = keys[i];
const char *val = g_hash_table_lookup(priv->data, key);
g_hash_table_iter_init(&iter, priv->data);
while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val)) {
if (!nm_setting_ovs_external_ids_check_key(key, &local)) { if (!nm_setting_ovs_external_ids_check_key(key, &local)) {
g_set_error(error, g_set_error(error,
NM_CONNECTION_ERROR, NM_CONNECTION_ERROR,