blob: cb669ec76cd841a9518feaf21a254ef64fb9375a [file] [log] [blame]
From 353de561a1f79ba36a71120f0390948daa7900eb Mon Sep 17 00:00:00 2001
From: Donald Yandt <donald.yandt@gmail.com>
Date: Tue, 28 May 2019 09:41:28 -0400
Subject: [PATCH] perf machine: Return NULL instead of null-terminating
/proc/version array
commit 34b65affe18daad31fed83e50d1f3b817786a2b7 upstream.
Return NULL instead of null-terminating version char array when fgets
fails due to end-of-file or error.
Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
Fixes: 30ba5b0e66c8 ("perf machine: Null-terminate version char array upon fgets(/proc/version) error")
Link: http://lkml.kernel.org/r/20190528134128.30841-1-donald.yandt@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 301bcce62e33..68a5c9b0d06a 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1216,9 +1216,9 @@ static char *get_kernel_version(const char *root_dir)
return NULL;
tmp = fgets(version, sizeof(version), file);
- if (!tmp)
- *version = '\0';
fclose(file);
+ if (!tmp)
+ return NULL;
name = strstr(version, prefix);
if (!name)
--
2.27.0