[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190514110100.22019-1-donald.yandt@gmail.com>
Date: Tue, 14 May 2019 07:01:00 -0400
From: Donald Yandt <donald.yandt@...il.com>
To: peterz@...radead.org
Cc: mingo@...hat.com, acme@...nel.org,
alexander.shishkin@...ux.intel.com, jolsa@...hat.com,
linux-kernel@...r.kernel.org, Donald Yandt <donald.yandt@...il.com>
Subject: [PATCH v2] tools/perf/util: null-terminate version char array upon error
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@...il.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 3c520baa1..28a9541c4 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
Powered by blists - more mailing lists