LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH resend] tools/perf/util/machine: Return NULL instead of null-terminating
@ 2019-05-28 13:41 Donald Yandt
  2019-05-30  8:14 ` [tip:perf/core] perf machine: Return NULL instead of null-terminating /proc/version array tip-bot for Donald Yandt
  0 siblings, 1 reply; 2+ messages in thread
From: Donald Yandt @ 2019-05-28 13:41 UTC (permalink / raw)
  To: peterz
  Cc: mingo, acme, alexander.shishkin, jolsa, yanmin_zhang,
	linux-kernel, Donald Yandt

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>
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 28a9541c4..6fd877220 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1235,9 +1235,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.20.1


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

* [tip:perf/core] perf machine: Return NULL instead of null-terminating /proc/version array
  2019-05-28 13:41 [PATCH resend] tools/perf/util/machine: Return NULL instead of null-terminating Donald Yandt
@ 2019-05-30  8:14 ` tip-bot for Donald Yandt
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Donald Yandt @ 2019-05-30  8:14 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: yanmin_zhang, jolsa, hpa, mingo, donald.yandt, linux-kernel,
	tglx, alexander.shishkin, peterz, acme

Commit-ID:  34b65affe18daad31fed83e50d1f3b817786a2b7
Gitweb:     https://git.kernel.org/tip/34b65affe18daad31fed83e50d1f3b817786a2b7
Author:     Donald Yandt <donald.yandt@gmail.com>
AuthorDate: Tue, 28 May 2019 09:41:28 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 28 May 2019 18:37:44 -0300

perf machine: Return NULL instead of null-terminating /proc/version array

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>
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index f5569f005cf3..17eec39e775e 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1241,9 +1241,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)

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 13:41 [PATCH resend] tools/perf/util/machine: Return NULL instead of null-terminating Donald Yandt
2019-05-30  8:14 ` [tip:perf/core] perf machine: Return NULL instead of null-terminating /proc/version array 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;
as well as URLs for NNTP newsgroup(s).