2014-07-26 22:53:06

by Rickard Strandqvist

[permalink] [raw]
Subject: [PATCH] tools: perf: util: parse-events.c: Cleaning up missing null-terminate in conjunction with strncpy

Ensures that the string is null-terminate in connection with the
use of strncpy. And removed unnecessary magic numbers.

Signed-off-by: Rickard Strandqvist <[email protected]>
---
tools/perf/util/parse-events.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 1e15df1..e2cd8c4 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -210,8 +210,12 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
}
strncpy(path->system, sys_dirent.d_name,
MAX_EVENT_LENGTH);
+ path->system[MAX_EVENT_LENGTH - 1] = '\0';
+
strncpy(path->name, evt_dirent.d_name,
MAX_EVENT_LENGTH);
+ path->name[MAX_EVENT_LENGTH - 1] = '\0';
+
return path;
}
}
@@ -1216,8 +1220,10 @@ static void print_symbol_events(const char *event_glob, unsigned type,

if (strlen(syms->alias))
snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
- else
+ else {
strncpy(name, syms->symbol, MAX_NAME_LEN);
+ name[MAX_NAME_LEN - 1] = '\0';
+ }

printf(" %-50s [%s]\n", name, event_type_descriptors[type]);

--
1.7.10.4