Skip to contentSkip to conversation

libtraceevent: Fix bug in tep_print_event()

PATCH New Yordan Karadzhov (VMware) 1 participant 1 message Jun 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libtraceevent: Fix bug in tep_print_event()

We must handle the case when the "tep_event" object is not found.

---
 src/event-parse.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
src/event-parse.c +11 -5
index de28b3b..f42ae38 100644
@@ -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, '%');
Signature · 1 line
2.27.0