Fix strcpy problems in api funtions, missing tests for the variable length

Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
---

 0 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/src/api.c b/src/api.c
index dfc70a4..2905fed 100644
--- a/src/api.c
+++ b/src/api.c
@@ -858,9 +858,13 @@ int cgroup_init(void)
                                continue;
                        }
 
-                       strcpy(cg_mount_table[found_mnt].name, controllers[i]);
-                       strcpy(cg_mount_table[found_mnt].mount.path,
-                                       ent->mnt_dir);
+                       strncpy(cg_mount_table[found_mnt].name,
+                               controllers[i], FILENAME_MAX);
+                       cg_mount_table[found_mnt].name[FILENAME_MAX-1] = '\0';
+                       strncpy(cg_mount_table[found_mnt].mount.path,
+                               ent->mnt_dir, FILENAME_MAX);
+                       cg_mount_table[found_mnt].mount.path[FILENAME_MAX-1] =
+                               '\0';
                        cg_mount_table[found_mnt].mount.next = NULL;
                        cgroup_dbg("Found cgroup option %s, count %d\n",
                                ent->mnt_opts, found_mnt);
@@ -897,9 +901,13 @@ int cgroup_init(void)
                                continue;
                        }
 
-                       strcpy(cg_mount_table[found_mnt].name, mntopt);
-                       strcpy(cg_mount_table[found_mnt].mount.path,
-                                       ent->mnt_dir);
+                       strncpy(cg_mount_table[found_mnt].name,
+                               mntopt, FILENAME_MAX);
+                       cg_mount_table[found_mnt].name[FILENAME_MAX-1] = '\0';
+                       strncpy(cg_mount_table[found_mnt].mount.path,
+                               ent->mnt_dir, FILENAME_MAX);
+                       cg_mount_table[found_mnt].mount.path[FILENAME_MAX-1] =
+                               '\0';
                        cg_mount_table[found_mnt].mount.next = NULL;
                        cgroup_dbg("Found cgroup option %s, count %d\n",
                                ent->mnt_opts, found_mnt);
@@ -2269,7 +2277,8 @@ static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t 
pid,
        /* Fill in cgroup details.  */
        cgroup_dbg("Will move pid %d to cgroup '%s'\n", pid, dest);
 
-       strcpy(cgroup->name, dest);
+       strncpy(cgroup->name, dest, FILENAME_MAX);
+       cgroup->name[FILENAME_MAX-1] = '\0';
 
        /* Scan all the controllers */
        for (i = 0; i < CG_CONTROLLER_MAX; i++) {


------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to