Skip to contentSkip to conversation

trace-cmd library: Do not read if cpu is greater than cpus

PATCH New Steven Rostedt 1 participant 1 message Apr 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd library: Do not read if cpu is greater than cpus

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

Fix tracecmd_read_data() to not read a cpu if it is greater than the number of CPUs recorded.

As tracecmd_cpus() returns the number of CPUs found in the system which can be greater than the number of CPUs stored in the buffer, it is likely that a caller will pass in a CPU number that is greater than the stored array of cpu_data.

In this case return NULL otherwise it will access beyond the cpu_data array.

Fixes 8724996990021 ("trace-cmd library: Read extended BUFFER option")
---
 lib/trace-cmd/trace-input.c | 3 +++
 1 file changed, 3 insertions(+)
lib/trace-cmd/trace-input.c +3 -0
index b8705ce364d1..425c6077d88e 100644
@@ -2462,6 +2462,9 @@ tracecmd_read_data(struct tracecmd_input *handle, int cpu)
 {
 	struct tep_record *record;
 
+	if (cpu >= handle->cpus)
+		return NULL;
+
 	record = tracecmd_peek_data(handle, cpu);
 	handle->cpu_data[cpu].next = NULL;
 	if (record) {
Signature · 1 line
2.35.1