]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Cleanup: Remove unnecessary strlen() in strncpy().
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Wed, 3 Jun 2009 06:01:56 +0000 (15:01 +0900)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 8 Jun 2009 07:56:31 +0000 (13:26 +0530)
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 <jsafrane@redhat.com>
Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Reviewed-By: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
src/api.c

index 4f88d202cc9d37331318fe1b0a2fa1eb05156c69..43f08d0f055bcce3da4a334c6d883214b43d213f 100644 (file)
--- 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. */