* Jan Safranek <[email protected]> [2010-06-07 11:58:46]:
> 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 <[email protected]>
> ---
>
> src/api.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/api.c b/src/api.c
> index 5409c9c..dcdd75b 100644
> --- 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);
I think we could potentially check to see if there was an overflow,
but I am not sure if this routine can handle that error case
correctly.
>
> fp = fopen(stat_file, "re");
> if (!fp) {
>
--
Three Cheers,
Balbir
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel