lkml.org 
[lkml]   [2019]   [May]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 20/73] perf machine: Null-terminate version char array upon fgets(/proc/version) error
Em Fri, May 17, 2019 at 08:05:39PM -0400, Donald Yandt escreveu:
> Thank you Arnaldo for signing my patch.
>
> I think we should use version 4 of my patch and return NULL instead of null-terminating for efficiency.

Please resubmit then, v3 is already upstream.

- Arnaldo

> Thanks,
>
> Donald
>
> > On May 17, 2019, at 3:35 PM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >
> > From: Donald Yandt <donald.yandt@gmail.com>
> >
> > If fgets() fails due to any other error besides end-of-file, the version
> > char array may not even be null-terminated.
> >
> > Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Avi Kivity <avi@scylladb.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
> > Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host")
> > Link: http://lkml.kernel.org/r/20190514110100.22019-1-donald.yandt@gmail.com
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> > tools/perf/util/machine.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> > index 3c520baa198c..28a9541c4835 100644
> > --- a/tools/perf/util/machine.c
> > +++ b/tools/perf/util/machine.c
> > @@ -1234,8 +1234,9 @@ static char *get_kernel_version(const char *root_dir)
> > if (!file)
> > return NULL;
> >
> > - version[0] = '\0';
> > tmp = fgets(version, sizeof(version), file);
> > + if (!tmp)
> > + *version = '\0';
> > fclose(file);
> >
> > name = strstr(version, prefix);
> > --
> > 2.20.1
> >

--

- Arnaldo

\
 
 \ /
  Last update: 2019-05-20 16:48    [W:0.071 / U:11.528 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site