public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tools/perf/util: null-terminate version char array upon error
@ 2019-05-14 11:01 Donald Yandt
  2019-05-14 13:36 ` Arnaldo Carvalho de Melo
  2019-05-18  8:59 ` [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error tip-bot for Donald Yandt
  0 siblings, 2 replies; 3+ messages in thread
From: Donald Yandt @ 2019-05-14 11:01 UTC (permalink / raw)
  To: peterz; +Cc: mingo, acme, alexander.shishkin, jolsa, linux-kernel,
	Donald Yandt

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>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-18  8:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-14 11:01 [PATCH v2] tools/perf/util: null-terminate version char array upon error Donald Yandt
2019-05-14 13:36 ` Arnaldo Carvalho de Melo
2019-05-18  8:59 ` [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error tip-bot for Donald Yandt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox