diff mbox series

[3/3] trace-cmd: Check the return of get_file_content() before calling add_reset_file()

Message ID 20190612182019.169932649@goodmis.org (mailing list archive)
State Accepted
Commit 7cf07883112fc1e3325addccf9127a815a2786ee
Headers show
Series trace-cmd: Fix some bugs that include issues with --max-graph-depth | expand

Commit Message

Steven Rostedt June 12, 2019, 6:19 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

If get_file_content() returns NULL, because the file does not exist or for
any other reason, it will cause add_reset_file() to trigger a SEGSEGV due to
using a NULL pointer. Only call add_reset_file() if get_file_content()
actually returns something.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Tzvetomir Stoyanov June 13, 2019, 2:51 p.m. UTC | #1
On Wed, Jun 12, 2019 at 9:19 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
>
> If get_file_content() returns NULL, because the file does not exist or for
> any other reason, it will cause add_reset_file() to trigger a SEGSEGV due to
> using a NULL pointer. Only call add_reset_file() if get_file_content()
> actually returns something.
>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---

Looks OK.
Reviewed-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>


>  tracecmd/trace-record.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
> index 2d716a81acbf..5dc6f17aa743 100644
> --- a/tracecmd/trace-record.c
> +++ b/tracecmd/trace-record.c
> @@ -270,8 +270,10 @@ static void reset_save_file(const char *file, int prio)
>         char *content;
>
>         content = get_file_content(file);
> -       add_reset_file(file, content, prio);
> -       free(content);
> +       if (content) {
> +               add_reset_file(file, content, prio);
> +               free(content);
> +       }
>  }
>
>  /*
> --
> 2.20.1
>
>


--

Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
diff mbox series

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 2d716a81acbf..5dc6f17aa743 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -270,8 +270,10 @@  static void reset_save_file(const char *file, int prio)
 	char *content;
 
 	content = get_file_content(file);
-	add_reset_file(file, content, prio);
-	free(content);
+	if (content) {
+		add_reset_file(file, content, prio);
+		free(content);
+	}
 }
 
 /*