From aec29957a768c7850ec5552ed4f31f44c4e366b2 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Wed, 3 Jun 2009 15:01:56 +0900 Subject: Cleanup: Remove unnecessary strlen() in strncpy(). Hi, CHANGELOG of v2: ================ * Specify the buffer size of 'user' instead of strlen(). It actually walks through 'user' twice, once to compute length by strlen() and then this patch specifies the buffer size of 'user' instead. Reported-by: Jan Safranek Signed-off-by: Ken'ichi Ohmichi Reviewed-By: Jan Safranek Signed-off-by: Dhaval Giani --- src/api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api.c b/src/api.c index 4f88d20..43f08d0 100644 --- a/src/api.c +++ b/src/api.c @@ -476,8 +476,9 @@ static int cgroup_parse_rules(bool cache, uid_t muid, gid_t mgid) newrule->uid = uid; newrule->gid = gid; - strncpy(newrule->name, user, strlen(user)); - strncpy(newrule->destination, destination, strlen(destination)); + strncpy(newrule->name, user, sizeof(newrule->name) - 1); + strncpy(newrule->destination, destination, + sizeof(newrule->destination) - 1); newrule->next = NULL; /* Parse the controller list, and add that to newrule too. */ -- cgit