diff mbox series

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

Message ID 20220404111812.2b3753df@gandalf.local.home (mailing list archive)
State Accepted
Commit ffee97c4750e38abdde0529cd37b1aca3681c14b
Headers show
Series trace-cmd library: Do not read if cpu is greater than cpus | expand

Commit Message

Steven Rostedt April 4, 2022, 3:18 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index b8705ce364d1..425c6077d88e 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -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) {