summaryrefslogtreecommitdiffstats
path: root/api.c
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-06-11 08:20:54 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-06-11 08:20:54 +0000
commitf00b82b6f9114694e3c05e2bb3a5395ce59c85de (patch)
tree2641e9182cf80d8c080299ff2992d314e2929be0 /api.c
parentf1bce06975c0c4d6b1e348bbd1cbc26694e57f82 (diff)
downloadlibcg-f00b82b6f9114694e3c05e2bb3a5395ce59c85de.tar.gz
libcg-f00b82b6f9114694e3c05e2bb3a5395ce59c85de.tar.xz
libcg-f00b82b6f9114694e3c05e2bb3a5395ce59c85de.zip
libcgroup: Fix segmentation fault in APIs.
Dan Smith reported some segmentation faults. It turns out that we did not NULL terminate all the structures when we had moved to the wrapper based approach. With this in mind, the loop checks the index instead of a NULL structure. Also remove unwanted NULL terminations. Thanks to Dan for excellent debugging. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/tags/v0.1c@77 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'api.c')
-rw-r--r--api.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/api.c b/api.c
index 6250ceb..0adeeb5 100644
--- a/api.c
+++ b/api.c
@@ -279,13 +279,11 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
fclose(tasks);
}
} else {
- for (i = 0; i <= CG_CONTROLLER_MAX &&
- cgroup->controller[i] != NULL; i++) {
+ for (i = 0; i < cgroup->index; i++) {
if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
return ECGROUPSUBSYSNOTMOUNTED;
}
- for (i = 0; i <= CG_CONTROLLER_MAX &&
- cgroup->controller[i] != NULL ; i++) {
+ for (i = 0; i <= cgroup->index; i++) {
if (!cg_build_path(cgroup->name, path,
cgroup->controller[i]->name))
continue;
@@ -412,21 +410,18 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
if (!cgroup_initialized)
return ECGROUPNOTINITALIZED;
- for (i = 0; i <= CG_CONTROLLER_MAX && cgroup->controller[i] != NULL;
- i++) {
+ for (i = 0; i < cgroup->index; i++) {
if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
return ECGROUPSUBSYSNOTMOUNTED;
}
- for (i = 0; i < CG_CONTROLLER_MAX && cgroup->controller[i];
- i++, strcpy(path, base)) {
+ for (i = 0; i < cgroup->index; i++, strcpy(path, base)) {
int j;
if (!cg_build_path(cgroup->name, base,
cgroup->controller[i]->name))
continue;
- for(j = 0; j < CG_NV_MAX &&
- cgroup->controller[i]->values[j];
- j++, strcpy(path, base)) {
+ for (j = 0; j < cgroup->controller[i]->index; j++,
+ strcpy(path, base)) {
strcat(path, cgroup->controller[i]->values[j]->name);
error = cg_set_control_value(path,
cgroup->controller[i]->values[j]->value);
@@ -455,8 +450,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
if (!cgroup_initialized)
return ECGROUPNOTINITALIZED;
- for (i = 0; i <= CG_CONTROLLER_MAX && cgroup->controller[i] != NULL;
- i++) {
+ for (i = 0; i < cgroup->index; i++) {
if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
return ECGROUPSUBSYSNOTMOUNTED;
}
@@ -472,7 +466,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
* subsystems mounted at one point, all of them *have* be on the cgroup
* data structure. If not, we fail.
*/
- for (k = 0; k < CG_CONTROLLER_MAX && cgroup->controller[k]; k++) {
+ for (k = 0; k < cgroup->index; k++) {
path[0] = '\0';
if (!cg_build_path(cgroup->name, path,
@@ -493,8 +487,8 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
if (error)
goto err;
- for (j = 0; j < CG_NV_MAX && cgroup->controller[k]->values[j];
- j++, strcpy(path, base)) {
+ for (j = 0; j < cgroup->controller[k]->index; j++,
+ strcpy(path, base)) {
strcat(path, cgroup->controller[k]->values[j]->name);
error = cg_set_control_value(path,
cgroup->controller[k]->values[j]->value);
@@ -538,13 +532,12 @@ int cgroup_delete_cgroup(struct cgroup *cgroup, int ignore_migration)
if (!cgroup_initialized)
return ECGROUPNOTINITALIZED;
- for (i = 0; i <= CG_CONTROLLER_MAX && cgroup->controller[i] != NULL;
- i++) {
+ for (i = 0; i < cgroup->index; i++) {
if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
return ECGROUPSUBSYSNOTMOUNTED;
}
- for (i = 0; i < CG_CONTROLLER_MAX && cgroup->controller; i++) {
+ for (i = 0; i < cgroup->index; i++) {
if (!cg_build_path(cgroup->name, path,
cgroup->controller[i]->name))
continue;
@@ -585,7 +578,7 @@ del_open_err:
fclose(base_tasks);
base_open_err:
if (ignore_migration) {
- for (i = 0; cgroup->controller[i] != NULL; i++) {
+ for (i = 0; i < cgroup->index; i++) {
if (!cg_build_path(cgroup->name, path,
cgroup->controller[i]->name))
continue;