all: reject duplicate keys in JSON

Teamd is not happy about them and would fail anyway. Worse even, if we
json_loads() such a JSON, which is precisely what happens when we inject the
"hwaddr" key, we turn bad JSON into a good one in a lossy matter. Not good.

https://bugzilla.redhat.com/show_bug.cgi?id=1455130
This commit is contained in:
Lubomir Rintel 2017-05-31 18:07:33 +02:00
parent 484d666485
commit c0419257e7
2 changed files with 4 additions and 4 deletions

View file

@ -4317,7 +4317,7 @@ nm_utils_is_json_object (const char *str, GError **error)
return FALSE;
}
json = json_loads (str, 0, &jerror);
json = json_loads (str, JSON_REJECT_DUPLICATES, &jerror);
if (!json) {
g_set_error (error,
NM_CONNECTION_ERROR,
@ -4369,9 +4369,9 @@ _nm_utils_team_config_equal (const char *conf1,
return TRUE;
/* A NULL configuration is equivalent to default value '{}' */
json1 = json_loads (conf1 ?: "{}", 0, &jerror);
json1 = json_loads (conf1 ?: "{}", JSON_REJECT_DUPLICATES, &jerror);
if (json1)
json2 = json_loads (conf2 ?: "{}", 0, &jerror);
json2 = json_loads (conf2 ?: "{}", JSON_REJECT_DUPLICATES, &jerror);
if (!json1 || !json2) {
ret = FALSE;

View file

@ -568,7 +568,7 @@ teamd_start (NMDevice *device, NMConnection *connection)
/* Inject the hwaddr property into the JSON configuration.
* While doing so, detect potential conflicts */
json = json_loads (config ?: "{}", 0, &jerror);
json = json_loads (config ?: "{}", JSON_REJECT_DUPLICATES, &jerror);
g_return_val_if_fail (json, FALSE);
hwaddr = json_object_get (json, "hwaddr");