Skip to contentSkip to conversation

trace-cmd: Prevent buffer overflow in update_pid_filters()

PATCH New Jerome Marchand 1 participant 1 message Oct 29, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Prevent buffer overflow in update_pid_filters()

The buffer in which the updated filter is written in update_pid_filters() is missing one byte to store the null character.

It fixes the following error:

$ trace-cmd start -e irq:* -e sched:* -P 1
*** buffer overflow detected ***: terminated
Aborted (core dumped)
---
 tracecmd/trace-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-record.c +1 -1
index a008cdfd..8726f9f4 100644
@@ -2851,7 +2851,7 @@ static void update_pid_filters(struct buffer_instance *instance)
 	if (fd < 0)
 		die("Failed to access set_event_pid");
 
-	len = instance->len_filter_pids + instance->nr_filter_pids;
+	len = instance->len_filter_pids + instance->nr_filter_pids + 1;
 	filter = malloc(len);
 	if (!filter)
 		die("Failed to allocate pid filter");
Signature · 1 line
2.47.0