Skip to contentSkip to conversation

trace-cmd report: Avoid crash on unknown event

PATCH In review Vincent Whitchurch 2 participants 4 messages Dec 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 trace-cmd report: Avoid crash on unknown event

Do not segfault if the event cannot be found for some reason and tep_find_event_by_record() returns NULL.

With this patch:

kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
[UNKNOWN EVENT][UNKNOWN EVENT] (NULL): [UNKNOWN EVENT]
kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...

---
 tracecmd/trace-read.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tracecmd/trace-read.c +3 -2
index 6f43c1d..df40b75 100644
@@ -142,12 +142,13 @@ static struct trace_hash wakeup_hash;
 static void print_event_name(struct trace_seq *s, struct tep_event *event)
 {
 	static const char *spaces = "                    "; /* 20 spaces */
+	const char *name = event ? event->name : "(NULL)";
 	int len;
 
-	trace_seq_printf(s, " %s: ", event->name);
+	trace_seq_printf(s, " %s: ", name);
 
 	/* Space out the event names evenly. */
-	len = strlen(event->name);
+	len = strlen(name);
 	if (len < 20)
 		trace_seq_printf(s, "%.*s", 20 - len, spaces);
 }
Signature · 1 line
2.20.1
#1 lore raw
Quoted 11 lines · On Wed, 8 Dec 2021 15:34:02 +0100 Vincent Whitchurch…

Do not segfault if the event cannot be found for some reason and tep_find_event_by_record() returns NULL.

With this patch:

kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
[UNKNOWN EVENT][UNKNOWN EVENT] (NULL): [UNKNOWN EVENT]
kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...

Hi Vincent,

I already applied the update.

https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/commit/?id=196a3a63c466204f3e8f4fa35194fc9ab7cb1ab7

Sorry, I waited a bit but your reply sounded like you wanted me to do it.

-- Steve

#2 lore raw
Quoted 15 lines · Steven Rostedt
Quoted 11 lines · On Wed, 8 Dec 2021 15:34:02 +0100 Vincent Whitchurch…

Do not segfault if the event cannot be found for some reason and tep_find_event_by_record() returns NULL.

With this patch:

kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
[UNKNOWN EVENT][UNKNOWN EVENT] (NULL): [UNKNOWN EVENT]
kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...

Quoted 7 lines

Hi Vincent,

I already applied the update.

https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/commit/?id=196a3a63c466204f3e8f4fa35194fc9ab7cb1ab7

Sorry, I waited a bit but your reply sounded like you wanted me to do it.

No worries, thanks. I did think it would be easier for you to commit it. I pulled before reworking the patch but I didn't see your commit. It turns out I was using a clone from the following (wrong) git which hasn't been updated in months...

https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git/

#3 lore raw
Quoted 6 lines · On Wed, 8 Dec 2021 16:00:05 +0100 Vincent Whitchurch…

No worries, thanks. I did think it would be easier for you to commit it. I pulled before reworking the patch but I didn't see your commit. It turns out I was using a clone from the following (wrong) git which hasn't been updated in months...

https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git/

Ug, I try to keep that one up to date. I have three repos for trace-cmd and two for libtracefs and libtraceevent (kernel.org and github). I've been focused on the libraries for some time, and after updating trace-cmd, I was thinking to myself "Hmm, isn't there another repo I update?"

I'll go and update that one too :-/

-- Steve