Hello, can you put here some test case? Ivana ----- Original Message ----- > From: "Peter Schiffer" <pschi...@redhat.com> > To: libcg-devel@lists.sourceforge.net > Sent: Wednesday, October 9, 2013 12:00:19 PM > Subject: [Libcg-devel] [PATCH] Fread() may crash when reading cgroup fs > > Use read() when reading from cgroup fs instead of fread(). > > Signed-off-by: Peter Schiffer <pschi...@redhat.com> > --- > src/api.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/src/api.c b/src/api.c > index 5fef990..2417d08 100644 > --- a/src/api.c > +++ b/src/api.c > @@ -2223,29 +2223,29 @@ static int cg_rd_ctrl_file(const char *subsys, const > char *cgroup, > const char *file, char **value) > { > char path[FILENAME_MAX]; > - FILE *ctrl_file = NULL; > - int ret; > + int ctrl_file = -1; > + ssize_t ret; > > if (!cg_build_path_locked(cgroup, path, subsys)) > return ECGFAIL; > > strncat(path, file, sizeof(path) - strlen(path)); > - ctrl_file = fopen(path, "re"); > - if (!ctrl_file) > + ctrl_file = open(path, O_RDONLY | O_CLOEXEC); > + if (ctrl_file < 0) > return ECGROUPVALUENOTEXIST; > > *value = calloc(CG_VALUE_MAX, 1); > if (!*value) { > - fclose(ctrl_file); > + close(ctrl_file); > last_errno = errno; > return ECGOTHER; > } > > /* > - * using %as crashes when we try to read from files like > + * using %as or fread crashes when we try to read from files like > * memory.stat > */ > - ret = fread(*value, 1, CG_VALUE_MAX-1, ctrl_file); > + ret = read(ctrl_file, *value, CG_VALUE_MAX-1); > if (ret < 0) { > free(*value); > *value = NULL; > @@ -2255,7 +2255,7 @@ static int cg_rd_ctrl_file(const char *subsys, const > char *cgroup, > (*value)[ret-1] = '\0'; > } > > - fclose(ctrl_file); > + close(ctrl_file); > > return 0; > } > > > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk > _______________________________________________ > Libcg-devel mailing list > Libcg-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libcg-devel >
------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel