diff mbox series

[7/8] trace-cmd input: Validate the input handle when copying from it

Message ID 20210301143857.694136727@goodmis.org (mailing list archive)
State Superseded
Headers show
Series trace-cmd: Fixes for trace-cmd restore | expand

Commit Message

Steven Rostedt March 1, 2021, 2:37 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Now that there's validation states, make sure that the input handle is at
the correct state to validate it.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 9a4b1f4e118a..53c2722f46e7 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -3491,6 +3491,10 @@  static int copy_header_files(struct tracecmd_input *handle, int fd)
 {
 	unsigned long long size;
 
+	/* The input handle has to have at least read the headers */
+	if (handle->file_state < TRACECMD_FILE_HEADERS)
+		return -1;
+
 	lseek64(handle->fd, handle->header_files_start, SEEK_SET);
 
 	/* "header_page"  */
@@ -3522,6 +3526,10 @@  static int copy_ftrace_files(struct tracecmd_input *handle, int fd)
 	unsigned int count;
 	unsigned int i;
 
+	/* The input handle has to have at least read the ftrace events */
+	if (handle->file_state < TRACECMD_FILE_FTRACE_EVENTS)
+		return -1;
+
 	if (read_copy_size4(handle, fd, &count) < 0)
 		return -1;
 
@@ -3545,6 +3553,10 @@  static int copy_event_files(struct tracecmd_input *handle, int fd)
 	unsigned int count;
 	unsigned int i,x;
 
+	/* The input handle has to have at least read all its events */
+	if (handle->file_state < TRACECMD_FILE_ALL_EVENTS)
+		return -1;
+
 	if (read_copy_size4(handle, fd, &systems) < 0)
 		return -1;
 
@@ -3577,6 +3589,10 @@  static int copy_proc_kallsyms(struct tracecmd_input *handle, int fd)
 {
 	unsigned int size;
 
+	/* The input handle has to have at least has kallsyms */
+	if (handle->file_state < TRACECMD_FILE_KALLSYMS)
+		return -1;
+
 	if (read_copy_size4(handle, fd, &size) < 0)
 		return -1;
 	if (!size)
@@ -3592,6 +3608,10 @@  static int copy_ftrace_printk(struct tracecmd_input *handle, int fd)
 {
 	unsigned int size;
 
+	/* The input handle has to have at least has printk stored */
+	if (handle->file_state < TRACECMD_FILE_PRINTK)
+		return -1;
+
 	if (read_copy_size4(handle, fd, &size) < 0)
 		return -1;
 	if (!size)
@@ -3607,6 +3627,10 @@  static int copy_command_lines(struct tracecmd_input *handle, int fd)
 {
 	unsigned long long size;
 
+	/* The input handle has to have at least read the cmdlines */
+	if (handle->file_state < TRACECMD_FILE_CMD_LINES)
+		return -1;
+
 	if (read_copy_size8(handle, fd, &size) < 0)
 		return -1;
 	if (!size)