]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Once we build the path, we don't have all the room in path anymore.
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Sat, 20 Sep 2008 00:56:09 +0000 (00:56 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Sat, 20 Sep 2008 00:56:09 +0000 (00:56 +0000)
Instead of using sizeof(path), we should use FILENAME_MAX -
strlen(path) - 1.

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@186 4f4bb910-9a46-0410-90c8-c897d4f1cd53

api.c

diff --git a/api.c b/api.c
index fef34c100c3b91d885eadab4facf9474007eedb3..fc7e18ab5c481b3eabf078b76cc88f3b02a2e871 100644 (file)
--- a/api.c
+++ b/api.c
@@ -293,7 +293,7 @@ static char *cg_build_path_locked(char *name, char *path, char *type)
        return NULL;
 }
 
-static char *cg_build_path(char *name, char *path, char *type)
+char *cg_build_path(char *name, char *path, char *type)
 {
        pthread_rwlock_rdlock(&cg_mount_table_lock);
        path = cg_build_path_locked(name, path, type);
@@ -1041,12 +1041,14 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
                 */
                struct cgroup_controller *cgc;
                struct stat stat_buffer;
+               int path_len;
 
                if (!cg_build_path_locked(NULL, path,
                                        cg_mount_table[i].name))
                        continue;
 
-               strncat(path, cgroup->name, sizeof(path));
+               path_len = strlen(path);
+               strncat(path, cgroup->name, FILENAME_MAX - path_len - 1);
 
                if (access(path, F_OK))
                        continue;