Blame SOURCES/libcgroup-0.41-coverity.patch

2ae3c9
diff --git a/src/api.c b/src/api.c
2ae3c9
index 1cd30df..93d0750 100644
2ae3c9
--- a/src/api.c
2ae3c9
+++ b/src/api.c
2ae3c9
@@ -3642,14 +3642,14 @@ static int cg_read_stat(FILE *fp, struct cgroup_stat *cgroup_stat)
2ae3c9
 		ret = ECGINVAL;
2ae3c9
 		goto out_free;
2ae3c9
 	}
2ae3c9
-	strncpy(cgroup_stat->name, token, FILENAME_MAX);
2ae3c9
+	strncpy(cgroup_stat->name, token, FILENAME_MAX - 1);
2ae3c9
 
2ae3c9
 	token = strtok_r(NULL, " ", &saveptr);
2ae3c9
 	if (!token) {
2ae3c9
 		ret = ECGINVAL;
2ae3c9
 		goto out_free;
2ae3c9
 	}
2ae3c9
-	strncpy(cgroup_stat->value, token, CG_VALUE_MAX);
2ae3c9
+	strncpy(cgroup_stat->value, token, CG_VALUE_MAX - 1);
2ae3c9
 
2ae3c9
 out_free:
2ae3c9
 	free(line);
2ae3c9
@@ -3906,9 +3906,9 @@ int cgroup_get_controller_next(void **handle, struct cgroup_mount_point *info)
2ae3c9
 		goto out_unlock;
2ae3c9
 	}
2ae3c9
 
2ae3c9
-	strncpy(info->name, cg_mount_table[*pos].name, FILENAME_MAX);
2ae3c9
+	strncpy(info->name, cg_mount_table[*pos].name, FILENAME_MAX - 1);
2ae3c9
 
2ae3c9
-	strncpy(info->path, cg_mount_table[*pos].mount.path, FILENAME_MAX);
2ae3c9
+	strncpy(info->path, cg_mount_table[*pos].mount.path, FILENAME_MAX - 1);
2ae3c9
 
2ae3c9
 	(*pos)++;
2ae3c9
 	*handle = pos;
2ae3c9
diff --git a/src/config.c b/src/config.c
2ae3c9
index e1ee0a8..c3004eb 100644
2ae3c9
--- a/src/config.c
2ae3c9
+++ b/src/config.c
2ae3c9
@@ -168,7 +168,7 @@ int config_insert_cgroup(char *cg_name, int flag)
2ae3c9
 	}
2ae3c9
 
2ae3c9
 	config_cgroup = &config_table[*table_index];
2ae3c9
-	strncpy(config_cgroup->name, cg_name, FILENAME_MAX);
2ae3c9
+	strncpy(config_cgroup->name, cg_name, FILENAME_MAX - 1);
2ae3c9
 
2ae3c9
 	/*
2ae3c9
 	 * Since this will be the last part to be parsed.
2ae3c9
@@ -1583,7 +1583,7 @@ int cgroup_config_create_template_group(struct cgroup *cgroup,
2ae3c9
 	int i, j, k;
2ae3c9
 	struct cgroup *t_cgroup;
2ae3c9
 	char buffer[FILENAME_MAX];
2ae3c9
-	struct cgroup *aux_cgroup;
2ae3c9
+	struct cgroup *aux_cgroup = NULL;
2ae3c9
 	struct cgroup_controller *cgc;
2ae3c9
 	int found;
2ae3c9
 
2ae3c9
@@ -1659,7 +1659,7 @@ int cgroup_config_create_template_group(struct cgroup *cgroup,
2ae3c9
 		/* no template is present for given name x controller pair
2ae3c9
 		 * add controller to result cgroup */
2ae3c9
 		aux_cgroup = cgroup_new_cgroup(cgroup->name);
2ae3c9
-		if (aux_cgroup) {
2ae3c9
+		if (aux_cgroup == NULL) {
2ae3c9
 			ret = ECGINVAL;
2ae3c9
 			fprintf(stderr, "cgroup %s can't be created\n",
2ae3c9
 				cgroup->name);
2ae3c9
@@ -1683,5 +1683,6 @@ int cgroup_config_create_template_group(struct cgroup *cgroup,
2ae3c9
 	}
2ae3c9
 
2ae3c9
 end:
2ae3c9
+	cgroup_free(&aux_cgroup);
2ae3c9
 	return ret;
2ae3c9
 }
2ae3c9
diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c
2ae3c9
index a0599c1..66e3bbc 100644
2ae3c9
--- a/src/tools/cgsnapshot.c
2ae3c9
+++ b/src/tools/cgsnapshot.c
2ae3c9
@@ -428,6 +428,7 @@ static int display_cgroup_data(struct cgroup *group,
2ae3c9
 				goto err;
2ae3c9
 			}
2ae3c9
 			fprintf(of, "\t\t%s=\"%s\";\n", output_name, value);
2ae3c9
+			free(value);
2ae3c9
 		}
2ae3c9
 		fprintf(of, "\t}\n");
2ae3c9
 	}
2ae3c9
diff --git a/src/wrapper.c b/src/wrapper.c
2ae3c9
index 0952823..599128f 100644
2ae3c9
--- a/src/wrapper.c
2ae3c9
+++ b/src/wrapper.c
2ae3c9
@@ -48,7 +48,7 @@ struct cgroup *cgroup_new_cgroup(const char *name)
2ae3c9
 		return NULL;
2ae3c9
 
2ae3c9
 	init_cgroup(cgroup);
2ae3c9
-	strncpy(cgroup->name, name, sizeof(cgroup->name));
2ae3c9
+	strncpy(cgroup->name, name, sizeof(cgroup->name) - 1);
2ae3c9
 
2ae3c9
 	return cgroup;
2ae3c9
 }
2ae3c9
@@ -82,7 +82,7 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup,
2ae3c9
 	if (!controller)
2ae3c9
 		return NULL;
2ae3c9
 
2ae3c9
-	strncpy(controller->name, name, sizeof(controller->name));
2ae3c9
+	strncpy(controller->name, name, sizeof(controller->name) - 1);
2ae3c9
 	controller->cgroup = cgroup;
2ae3c9
 	controller->index = 0;
2ae3c9
 
2ae3c9
@@ -560,7 +560,7 @@ struct cgroup *create_cgroup_from_name_value_pairs(const char *name,
2ae3c9
 			goto scgroup_err;
2ae3c9
 		}
2ae3c9
 
2ae3c9
-		strncpy(con, name_value[i].name, FILENAME_MAX);
2ae3c9
+		strncpy(con, name_value[i].name, FILENAME_MAX - 1);
2ae3c9
 		strtok(con, ".");
2ae3c9
 
2ae3c9
 		/* find out whether we have to add the controller or
2ae3c9
diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c
2ae3c9
index acc229a..d7770a0 100644
2ae3c9
--- a/tests/libcgrouptest01.c
2ae3c9
+++ b/tests/libcgrouptest01.c
2ae3c9
@@ -60,11 +60,11 @@ int main(int argc, char *argv[])
2ae3c9
 	if (fs_mounted) {
2ae3c9
 		ctl1 = atoi(argv[2]);
2ae3c9
 		ctl2 = atoi(argv[3]);
2ae3c9
-		strncpy(mountpoint, argv[4], sizeof(mountpoint));
2ae3c9
+		strncpy(mountpoint, argv[4], sizeof(mountpoint) - 1);
2ae3c9
 		cgroup_dbg("C:DBG: mountpoint1 as recieved from script=%s\n",
2ae3c9
 								 mountpoint);
2ae3c9
 		if (fs_mounted == FS_MULTI_MOUNTED) {
2ae3c9
-			strncpy(mountpoint2, argv[5], sizeof(mountpoint2));
2ae3c9
+			strncpy(mountpoint2, argv[5], sizeof(mountpoint2) - 1);
2ae3c9
 			cgroup_dbg("C:DBG: mountpoint2 as recieved from "
2ae3c9
 					"script=%s\n", mountpoint2);
2ae3c9
 		}
2ae3c9
diff --git a/tests/read_stats.c b/tests/read_stats.c
2ae3c9
index a1bc244..0583039 100644
2ae3c9
--- a/tests/read_stats.c
2ae3c9
+++ b/tests/read_stats.c
2ae3c9
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
2ae3c9
 	}
2ae3c9
 
2ae3c9
 	root_len = strlen(info.full_path) - 1;
2ae3c9
-	strncpy(cgroup_path, info.path, FILENAME_MAX);
2ae3c9
+	strncpy(cgroup_path, info.path, FILENAME_MAX - 1);
2ae3c9
 	ret = read_stats(cgroup_path, controller);
2ae3c9
 	if (ret < 0)
2ae3c9
 		exit(EXIT_FAILURE);
2ae3c9
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
2ae3c9
 			ECGEOF) {
2ae3c9
 		if (info.type != CGROUP_FILE_TYPE_DIR)
2ae3c9
 			continue;
2ae3c9
-		strncpy(cgroup_path, info.full_path + root_len, FILENAME_MAX);
2ae3c9
+		strncpy(cgroup_path, info.full_path + root_len, FILENAME_MAX - 1);
2ae3c9
 		strcat(cgroup_path, "/");
2ae3c9
 		ret = read_stats(cgroup_path, controller);
2ae3c9
 		if (ret < 0)
2ae3c9
diff --git a/tests/test_functions.c b/tests/test_functions.c
2ae3c9
index 8f1d59e..f357ab2 100644
2ae3c9
--- a/tests/test_functions.c
2ae3c9
+++ b/tests/test_functions.c
2ae3c9
@@ -139,7 +139,7 @@ struct cgroup *create_new_cgroup_ds(int ctl, const char *grpname,
2ae3c9
 	char group[FILENAME_MAX];
2ae3c9
 	char controller_name[FILENAME_MAX], control_file[FILENAME_MAX];
2ae3c9
 
2ae3c9
-	strncpy(group, grpname, sizeof(group));
2ae3c9
+	strncpy(group, grpname, sizeof(group) - 1);
2ae3c9
 	retval = set_controller(ctl, controller_name, control_file);
2ae3c9
 	if (retval) {
2ae3c9
 		fprintf(stderr, "Setting controller failled\n");