]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Fix overlaping src and dest buffers in sprintf()
authorJan Safranek <jsafrane@redhat.com>
Mon, 7 Jun 2010 09:58:46 +0000 (11:58 +0200)
committerDhaval Giani <dhaval.giani@gmail.com>
Tue, 6 Jul 2010 13:06:47 +0000 (15:06 +0200)
libcgroup compiled with various optimization flags produce strange results
when sprintf's destination and source pointers overlap or are the same.

In addition, use strncpy() instead. This is more or less useless, because
cg_build_path() does not check sizes either, but just for my personal feeling
of correct C code...

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
src/api.c

index 5409c9c21eb0b7e40d0c7227df13b4bb045d8132..dcdd75b4bde35821ba0b04568b812c753e9826cb 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -2848,6 +2848,7 @@ int cgroup_read_stats_begin(const char *controller, const char *path,
 {
        int ret = 0;
        char stat_file[FILENAME_MAX];
+       char stat_path[FILENAME_MAX];
        FILE *fp;
 
        if (!cgroup_initialized)
@@ -2856,10 +2857,11 @@ int cgroup_read_stats_begin(const char *controller, const char *path,
        if (!cgroup_stat || !handle)
                return ECGINVAL;
 
-       if (!cg_build_path(path, stat_file, controller))
+       if (!cg_build_path(path, stat_path, controller))
                return ECGOTHER;
 
-       sprintf(stat_file, "%s/%s.stat", stat_file, controller);
+       snprintf(stat_file, sizeof(stat_file), "%s/%s.stat", stat_path,
+                       controller);
 
        fp = fopen(stat_file, "re");
        if (!fp) {