Skip to contentSkip to conversation

tools/perf/util: null-terminate version char array upon error

PATCH Superseded Donald Yandt 1 participant 1 message May 14, 2019

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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.

Fixes a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host")
---
 tools/perf/util/machine.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +2 -1
index 3c520baa1..28a9541c4 100644
@@ -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