* Jiri Slaby <jsl...@suse.cz[2011-01-04 17:56:39]:

The 'n' parameter in strncat stands for how much to copy from src, not
what's dest overall space. So we need to subtract full strlen we have
constructed so far.

Also fix one strncpy where we may pass too much as well as in strncpy.

Signed-off-by: Jiri Slaby <jsl...@suse.cz>
---
 src/tools/cgsnapshot.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c
index b223970..88f2142 100644
--- a/src/tools/cgsnapshot.c
+++ b/src/tools/cgsnapshot.c
@@ -209,7 +209,7 @@ static int display_permissions(const char *path,
        /* get tasks file statistic */
        strncpy(tasks_path, path, FILENAME_MAX);
        tasks_path[FILENAME_MAX-1] = '\0';
-       strncat(tasks_path, "/tasks", FILENAME_MAX);
+       strncat(tasks_path, "/tasks", FILENAME_MAX - strlen(tasks_path) - 1);
        tasks_path[FILENAME_MAX-1] = '\0';
        ret = stat(tasks_path, &sbt);
        if (ret) {
@@ -332,11 +332,15 @@ static int display_cgroup_data(struct cgroup *group,
                           variable files in the root group to find out
                           whether the variable is writable.
                         */
+                       if (root_path_len >= FILENAME_MAX)
+                               root_path_len = FILENAME_MAX - 1;
                        strncpy(var_path, group_path, root_path_len);
                        var_path[root_path_len] = '\0';
-                       strncat(var_path, "/", FILENAME_MAX);
+                       strncat(var_path, "/", FILENAME_MAX -
+                                       strlen(var_path) - 1);
                        var_path[FILENAME_MAX-1] = '\0';
-                       strncat(var_path, name, FILENAME_MAX);
+                       strncat(var_path, name, FILENAME_MAX -
+                                       strlen(var_path) - 1);
                        var_path[FILENAME_MAX-1] = '\0';

                        /* test whether the  write permissions */
-- 
1.7.3.4



-- 
        Three Cheers,
        Balbir

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to