File 0020-teamdctl-unmess-check_teamd_team_devname-and-fix-dou.patch of Package libteam

From 3cb18900b1c0dfdf1131ce7ec1298d5c1511c248 Mon Sep 17 00:00:00 2001
From: Jiri Pirko <jiri@resnulli.us>
Date: Fri, 28 Mar 2014 19:26:25 +0100
Subject: [patch libteam] teamdctl: unmess check_teamd_team_devname and fix
 double free there

json_decref(j_device_name) was incorrectly called because
json_object_get() returns borrowed reference.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 utils/teamdctl.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/utils/teamdctl.c b/utils/teamdctl.c
index ee5be75..5d1228e 100644
--- a/utils/teamdctl.c
+++ b/utils/teamdctl.c
@@ -886,26 +886,30 @@ static int check_team_devname(char *team_devname)
 static int check_teamd_team_devname(struct teamdctl *tdc,
 				    const char *team_devname)
 {
-	int ret = 0;
-	json_t* root;
-	json_error_t error;
-	json_t* j_device_name;
-	const char* teamd_device_name;
-
-	root = json_loads(teamdctl_config_get_raw(tdc), 0, &error);
-	j_device_name = json_object_get(root, "device");
+	json_t *dump_json;
+	char *devname;
+	int err;
 
-	teamd_device_name = json_string_value(j_device_name);
+	err = __jsonload(&dump_json, teamdctl_config_get_raw(tdc));
+	if (err)
+		return err;
+	err = json_unpack(dump_json, "{s:s}", "device", &devname);
+	if (err) {
+		pr_err("Failed to parse device name from config.\n");
+		err = -EINVAL;
+		goto free_json;
+	}
 
-	if (strcmp(team_devname, teamd_device_name) != 0) {
-		pr_err("Unable to access to %s through connected teamd daemon because daemon controls %s.\n",
-		       team_devname, teamd_device_name);
-		ret = -1;
+	if (strcmp(team_devname, devname)) {
+		pr_err("Unable to access to %s through connected teamd daemon because it controls %s.\n",
+		       team_devname, devname);
+		err = -EINVAL;
+		goto free_json;
 	}
 
-	json_decref(j_device_name);
-	json_decref(root);
-	return ret;
+free_json:
+	json_decref(dump_json);
+	return err;
 }
 
 static int call_command(struct teamdctl *tdc, int argc, char **argv,
@@ -1062,7 +1066,8 @@ int main(int argc, char **argv)
 		goto teamdctl_free;
 	}
 
-	if (check_teamd_team_devname(tdc, team_devname)) {
+	err = check_teamd_team_devname(tdc, team_devname);
+	if (err) {
 		ret = EXIT_FAILURE;
 		goto teamdctl_disconnect;
 	}
-- 
1.9.0