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

From: Rickard Strandqvist
Date: Sat Jul 26 2014 - 18:53:10 EST


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

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/