Skip to contentSkip to conversation

libtraceevent: Handle case of unknown operator

PATCH In review Steven Rostedt 2 participants 2 messages Nov 19, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceevent: Handle case of unknown operator

From: "Steven Rostedt (Google)" <[email protected]>

The m68k architecture had a trace event with "m68k_memory[0].addr >> 13" in it. The parsing after the ']' and before the '.' checked the priority of the '.' but because it does not handle '.' as an operator it returned a negative number. But process_op() did not check for an error and continued processing. This caused a segfault.

Return immediately if the operator is not handled by get_op_prio().

Fixes 6582b0aea1cc ("tools/events: Add files to create libtraceevent.a")
---
 src/event-parse.c | 4 ++++
 1 file changed, 4 insertions(+)
src/event-parse.c +4 -0
index 0427061603db..a6da8f04cbf3 100644
@@ -2498,6 +2498,10 @@ process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok)
 
 		/* higher prios need to be closer to the root */
 		prio = get_op_prio(*tok);
+		if (prio < 0) {
+			token = *tok;
+			goto out_free;
+		}
 
 		if (prio > arg->op.prio)
 			return process_op(event, arg, tok);
Signature · 1 line
2.45.2
Tested-by on v1 1/1
#1 lore raw

Hello Steve,

Quoted 8 lines · Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

The m68k architecture had a trace event with "m68k_memory[0].addr >> 13" in it. The parsing after the ']' and before the '.' checked the priority of the '.' but because it does not handle '.' as an operator it returned a negative number. But process_op() did not check for an error and continued processing. This caused a segfault.

Quoted 7 lines

Return immediately if the operator is not handled by get_op_prio().

Fixes 6582b0aea1cc ("tools/events: Add files to create libtraceevent.a")

Thank you for your patch !

Quoted 19 lines
---
  src/event-parse.c | 4 ++++
  1 file changed, 4 insertions(+)
src/event-parse.c +4 -0
index 0427061603db..a6da8f04cbf3 100644
@@ -2498,6 +2498,10 @@ process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok)
 
  		/* higher prios need to be closer to the root */
  		prio = get_op_prio(*tok);
+		if (prio < 0) {
+			token = *tok;
+			goto out_free;
+		}
 
  		if (prio > arg->op.prio)
  			return process_op(event, arg, tok);