From: Ken'ichi Ohmichi Date: Wed, 3 Jun 2009 06:01:56 +0000 (+0900) Subject: Cleanup: Remove unnecessary strlen() in strncpy(). X-Git-Tag: v0.34~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aec29957a768c7850ec5552ed4f31f44c4e366b2;p=thirdparty%2Flibcgroup.git 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 --- diff --git a/src/api.c b/src/api.c index 4f88d202..43f08d0f 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. */