lkml.org 
[lkml]   [2019]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v4] tools/perf/util: null-terminate version char array upon error
Date
If fgets fails due to any other error besides end-of-file, the version char array may not even be null-terminated.

Changes from v1-3:
* close file, then return NULL instead of null-terminating version char array

Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host")
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..6fd877220 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1234,9 +1234,10 @@ static char *get_kernel_version(const char *root_dir)
if (!file)
return NULL;

- version[0] = '\0';
tmp = fgets(version, sizeof(version), file);
fclose(file);
+ if (!tmp)
+ return NULL;

name = strstr(version, prefix);
if (!name)
--
2.20.1
\
 
 \ /
  Last update: 2019-05-14 22:54    [W:0.023 / U:2.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site