From c0419257e70cc64c889a9a906445a74efb92dc44 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 31 May 2017 18:07:33 +0200 Subject: [PATCH] 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 --- libnm-core/nm-utils.c | 6 +++--- src/devices/team/nm-device-team.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index dedad241ad..8f08c1b566 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -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; diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 1c4d2ef6d2..c457e91242 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -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");