Skip to contentSkip to conversation

perf: fix strlen() bug in perf_event__synthesize_event_type() (repost)

PATCH In review Stephane Eranian 1 participant 3 messages Jan 20, 2012 – Jan 31, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: fix strlen() bug in perf_event__synthesize_event_type() (repost)

[repost because of typo in Ingo's email address]

The event_type record has a max length for the event name. It's called MAX_EVENT_NAME.

The name may be truncated to fit the max length. But the header.size still reflects the original name length. If that length is > MAX_EVENT_NAME, then the header.size field is bogus. Fix this by using the length of the name after the potential truncation.

---

tools/perf/util/header.c +1 -1
index 3e7e0b0..ecd7f4d 100644
@@ -2105,7 +2105,7 @@ int perf_event__synthesize_event_type(struct perf_tool *tool,
 	strncpy(ev.event_type.event_type.name, name, MAX_EVENT_NAME - 1);
 
 	ev.event_type.header.type = PERF_RECORD_HEADER_EVENT_TYPE;
-	size = strlen(name);
+	size = strlen(ev.event_type.event_type.name);
 	size = ALIGN(size, sizeof(u64));
 	ev.event_type.header.size = sizeof(ev.event_type) -
 		(sizeof(ev.event_type.event_type.name) - size);
#1 lore raw

[tip:perf/core] perf tools: Fix strlen() bug in perf_event__synthesize_event_type()

Commit-ID:  f8f4b2872295dca88339ec0c403b2217b1197353
Gitweb:     http://git.kernel.org/tip/f8f4b2872295dca88339ec0c403b2217b1197353
Author:     Stephane Eranian <[email protected]>
AuthorDate: Fri, 20 Jan 2012 10:49:12 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 24 Jan 2012 20:31:34 -0200

perf tools: Fix strlen() bug in perf_event__synthesize_event_type()

The event_type record has a max length for the event name.

It's called MAX_EVENT_NAME.

The name may be truncated to fit the max length. But the header.size still reflects the original name length. If that length is > MAX_EVENT_NAME, then the header.size field is bogus. Fix this by using the length of the name after the potential truncation.

---
 tools/perf/util/header.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/header.c +1 -1
index 3e7e0b0..ecd7f4d 100644
@@ -2105,7 +2105,7 @@ int perf_event__synthesize_event_type(struct perf_tool *tool,
 	strncpy(ev.event_type.event_type.name, name, MAX_EVENT_NAME - 1);
 
 	ev.event_type.header.type = PERF_RECORD_HEADER_EVENT_TYPE;
-	size = strlen(name);
+	size = strlen(ev.event_type.event_type.name);
 	size = ALIGN(size, sizeof(u64));
 	ev.event_type.header.size = sizeof(ev.event_type) -
 		(sizeof(ev.event_type.event_type.name) - size);
#2 lore raw

[tip:perf/core] perf tools: Fix strlen() bug in perf_event__synthesize_event_type()

In reply to Stephane Eranian
Commit-ID:  d8d9c282a1abbe2baf6d22f959e6adf4c90629bf
Gitweb:     http://git.kernel.org/tip/d8d9c282a1abbe2baf6d22f959e6adf4c90629bf
Author:     Stephane Eranian <[email protected]>
AuthorDate: Fri, 20 Jan 2012 10:49:12 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 30 Jan 2012 22:29:12 -0200

perf tools: Fix strlen() bug in perf_event__synthesize_event_type()

The event_type record has a max length for the event name.

It's called MAX_EVENT_NAME.

The name may be truncated to fit the max length. But the header.size still reflects the original name length. If that length is > MAX_EVENT_NAME, then the header.size field is bogus. Fix this by using the length of the name after the potential truncation.

---
 tools/perf/util/header.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/header.c +1 -1
index 3e7e0b0..ecd7f4d 100644
@@ -2105,7 +2105,7 @@ int perf_event__synthesize_event_type(struct perf_tool *tool,
 	strncpy(ev.event_type.event_type.name, name, MAX_EVENT_NAME - 1);
 
 	ev.event_type.header.type = PERF_RECORD_HEADER_EVENT_TYPE;
-	size = strlen(name);
+	size = strlen(ev.event_type.event_type.name);
 	size = ALIGN(size, sizeof(u64));
 	ev.event_type.header.size = sizeof(ev.event_type) -
 		(sizeof(ev.event_type.event_type.name) - size);