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>
{
int ret = 0;
char stat_file[FILENAME_MAX];
+ char stat_path[FILENAME_MAX];
FILE *fp;
if (!cgroup_initialized)
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) {