libnm: guard against empty attribute names for NMLldpNeighbor

The libnm API NMLldpNeighbor does not accept "" as an attribute name.
And it does not need to, because a reasonable NetworkManager should
never expose such names.

However, we should not trust NetworkManager to be reasonable. Check that
the attribute name is not empty.
This commit is contained in:
Thomas Haller 2021-03-12 09:42:38 +01:00
parent 84d64217f8
commit cba3113607
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -247,8 +247,13 @@ _notify_update_prop_lldp_neighbors(NMClient * client,
/* Note that there is no public API to mutate a NMLldpNeighbor instance.
* This is the only place where we actually mutate it. */
neigh = nm_lldp_neighbor_new();
while (g_variant_iter_next(attrs_iter, "{&sv}", &attr_name, &attr_variant))
while (g_variant_iter_next(attrs_iter, "{&sv}", &attr_name, &attr_variant)) {
if (attr_name[0] == '\0') {
g_variant_unref(attr_variant);
continue;
}
g_hash_table_insert(neigh->attrs, g_strdup(attr_name), attr_variant);
}
g_ptr_array_add(new, neigh);