diff mbox series

[v2] libtraceevent: Fix bug in tep_print_event()

Message ID 20210630193714.27338-1-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit 6accb556368fbe091460d992da486ddda0fa8ce3
Headers show
Series [v2] libtraceevent: Fix bug in tep_print_event() | expand

Commit Message

Yordan Karadzhov June 30, 2021, 7:37 p.m. UTC
We must handle the case when the "tep_event" object is not found.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/event-parse.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index de28b3b..f42ae38 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -6418,17 +6418,23 @@  void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
 		     struct tep_record *record, const char *fmt, ...)
 {
 	struct print_event_type type;
-	char *format = strdup(fmt);
-	char *current = format;
-	char *str = format;
+	struct tep_event *event;
+	char *current;
+	char *format;
+	char *str;
 	int offset;
 	va_list args;
-	struct tep_event *event;
 
+	event = tep_find_event_by_record(tep, record);
+	if (!event) {
+		trace_seq_printf(s, "[UNKNOWN EVENT]");
+		return;
+	}
+
+	str = current = format = strdup(fmt);
 	if (!format)
 		return;
 
-	event = tep_find_event_by_record(tep, record);
 	va_start(args, fmt);
 	while (*current) {
 		current = strchr(str, '%');