2022-05-13 14:30:15

by Wangshaobo (bobo)

[permalink] [raw]
Subject: [PATCH 0/2] tools libtraceevent fixes

tools libtraceevent fixes

Wang ShaoBo (2):
libtraceevent: fix memleak in make_bprint_args()
libtraceevent: fix free NULL pointer in parse_arg_add()

tools/lib/traceevent/event-parse.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

--
2.25.1



2022-05-13 20:39:27

by Wangshaobo (bobo)

[permalink] [raw]
Subject: [PATCH 2/2] libtraceevent: fix free NULL pointer in parse_arg_add()

Should not call free if parg->format is NULL.

Fixes: e7a90882b05b ("tools lib traceevent: Optimize pretty_print() function")
Signed-off-by: Wang ShaoBo <[email protected]>
---
tools/lib/traceevent/event-parse.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 69e4d5229362..b1a07db54457 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -5461,9 +5461,11 @@ static int parse_arg_add(struct tep_print_parse **parse, char *format,
return 0;
error:
if (parg) {
- free(parg->format);
+ if (parg->format)
+ free(parg->format);
free(parg);
}
+
return -1;
}

--
2.25.1


2022-05-14 00:53:24

by Wangshaobo (bobo)

[permalink] [raw]
Subject: [PATCH 1/2] libtraceevent: fix memleak in make_bprint_args()

Release arg allocated from alloc_arg() when strdup failed in make_bprint_args().

Fixes: a6d2a61ac653 ("tools lib traceevent: Remove some die() calls")
Signed-off-by: Wang ShaoBo <[email protected]>
---
tools/lib/traceevent/event-parse.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 8e24c4c78c7f..69e4d5229362 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4507,8 +4507,10 @@ static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, s
arg->next = NULL;
arg->type = TEP_PRINT_BSTRING;
arg->string.string = strdup(bptr);
- if (!arg->string.string)
+ if (!arg->string.string) {
+ free(arg);
goto out_free;
+ }
bptr += strlen(bptr) + 1;
*next = arg;
next = &arg->next;
--
2.25.1


2022-05-25 16:48:54

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 0/2] tools libtraceevent fixes

On Fri, 13 May 2022 10:33:06 +0800
Wang ShaoBo <[email protected]> wrote:

> tools libtraceevent fixes
>
> Wang ShaoBo (2):
> libtraceevent: fix memleak in make_bprint_args()
> libtraceevent: fix free NULL pointer in parse_arg_add()

These fixes need to be sent to [email protected], and
applied against libtraceevent:

https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/

Arnaldo,

libtraceevent is now in most distros. Can we now deprecate the version in
the kernel as it is no longer actively maintained?

-- Steve


>
> tools/lib/traceevent/event-parse.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>


2022-06-17 21:50:15

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 2/2] libtraceevent: fix free NULL pointer in parse_arg_add()

On Fri, 13 May 2022 10:33:08 +0800
Wang ShaoBo <[email protected]> wrote:

> Should not call free if parg->format is NULL.
>
> Fixes: e7a90882b05b ("tools lib traceevent: Optimize pretty_print() function")
> Signed-off-by: Wang ShaoBo <[email protected]>
> ---
> tools/lib/traceevent/event-parse.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index 69e4d5229362..b1a07db54457 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -5461,9 +5461,11 @@ static int parse_arg_add(struct tep_print_parse **parse, char *format,
> return 0;
> error:
> if (parg) {
> - free(parg->format);
> + if (parg->format)
> + free(parg->format);

It's perfectly fine to call free(NULL).

This is not a bug fix.

-- Steve

> free(parg);
> }
> +
> return -1;
> }
>

2022-06-17 22:00:06

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 1/2] libtraceevent: fix memleak in make_bprint_args()

On Fri, 13 May 2022 10:33:07 +0800
Wang ShaoBo <[email protected]> wrote:

> Release arg allocated from alloc_arg() when strdup failed in make_bprint_args().
>
> Fixes: a6d2a61ac653 ("tools lib traceevent: Remove some die() calls")
> Signed-off-by: Wang ShaoBo <[email protected]>
> ---
> tools/lib/traceevent/event-parse.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index 8e24c4c78c7f..69e4d5229362 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -4507,8 +4507,10 @@ static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, s
> arg->next = NULL;
> arg->type = TEP_PRINT_BSTRING;
> arg->string.string = strdup(bptr);
> - if (!arg->string.string)
> + if (!arg->string.string) {
> + free(arg);
> goto out_free;

This is a fix, thank you. But libtraceevent now lives here:

https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/

I'll port this patch to that.

Thanks,

-- Steve

> + }
> bptr += strlen(bptr) + 1;
> *next = arg;
> next = &arg->next;