From 50c907274a3e36db3b9819dc4f0e303ba903a3fa Mon Sep 17 00:00:00 2001 From: Dhaval Giani Date: Sat, 9 Aug 2008 09:25:22 +0000 Subject: [PATCH] libcgroup: Fix index values in cgroup_add_value_* There is a horrible bug in wrapper.c. The loop was causing a segmentation fault. This is because we were checking for index value as opposed to i. This bug was not hit before, because in all our testing, we were trying out only with CONFIG_FAIR_GROUP_SCHED and we were setting only one value inside the memory subsystem. Signed-off-by: Dhaval Giani git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@121 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- wrapper.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/wrapper.c b/wrapper.c index 35031941..7fa85d33 100644 --- a/wrapper.c +++ b/wrapper.c @@ -112,8 +112,7 @@ int cgroup_add_value_string(struct cgroup_controller *controller, return ECGMAXVALUESEXCEEDED; for (i = 0; i < controller->index && i < CG_VALUE_MAX; i++) { - if (strncmp(controller->values[controller->index]->name, name, - sizeof(controller->values[controller->index]->name)) == 0) + if (!strcmp(controller->values[i]->name, name)) return ECGVALUEEXISTS; } @@ -142,8 +141,7 @@ int cgroup_add_value_int64(struct cgroup_controller *controller, return ECGMAXVALUESEXCEEDED; for (i = 0; i < controller->index && i < CG_VALUE_MAX; i++) { - if (strncmp(controller->values[controller->index]->name, name, - sizeof(controller->values[controller->index]->name)) == 0) + if (!strcmp(controller->values[i]->name, name)) return ECGVALUEEXISTS; } @@ -178,8 +176,7 @@ int cgroup_add_value_uint64(struct cgroup_controller *controller, return ECGMAXVALUESEXCEEDED; for (i = 0; i < controller->index && i < CG_VALUE_MAX; i++) { - if (strncmp(controller->values[controller->index]->name, name, - sizeof(controller->values[controller->index]->name)) == 0) + if (!strcmp(controller->values[i]->name, name)) return ECGVALUEEXISTS; } @@ -212,8 +209,7 @@ int cgroup_add_value_bool(struct cgroup_controller *controller, return ECGMAXVALUESEXCEEDED; for (i = 0; i < controller->index && i < CG_VALUE_MAX; i++) { - if (strncmp(controller->values[controller->index]->name, name, - sizeof(controller->values[controller->index]->name)) == 0) + if (!strcmp(controller->values[i]->name, name)) return ECGVALUEEXISTS; } -- 2.47.2