diff mbox series

libtraceevent: Reset field properly in event_read_fields()

Message ID 20220607045925.814164-1-namhyung@kernel.org (mailing list archive)
State Accepted
Commit 501695160aebe18e905456fa5562cfda42864cc2
Headers show
Series libtraceevent: Reset field properly in event_read_fields() | expand

Commit Message

Namhyung Kim June 7, 2022, 4:59 a.m. UTC
The field pointer is allocated and added to the fields list in a
loop.  But it might refer the previous one if it fails to parse before
allocating a new one.

In that case, it would free the previous field but didn't update the
link of the list for the one before it.  Moreover, it doesn't need to
free the previous one as it finished ok.  Let's reset the field
pointer at the end of each iteration so that it cannot see the
previous one.

This was found by a fuzz test with an event having only one field.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 src/event-parse.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Steven Rostedt June 8, 2022, 3:17 p.m. UTC | #1
On Mon,  6 Jun 2022 21:59:25 -0700
Namhyung Kim <namhyung@kernel.org> wrote:

> The field pointer is allocated and added to the fields list in a
> loop.  But it might refer the previous one if it fails to parse before
> allocating a new one.
> 
> In that case, it would free the previous field but didn't update the
> link of the list for the one before it.  Moreover, it doesn't need to
> free the previous one as it finished ok.  Let's reset the field
> pointer at the end of each iteration so that it cannot see the
> previous one.
> 
> This was found by a fuzz test with an event having only one field.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Applied. Thanks Namhyung!

-- Steve


> ---
>  src/event-parse.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/event-parse.c b/src/event-parse.c
> index 8f4fb59..1ba2a78 100644
> --- a/src/event-parse.c
> +++ b/src/event-parse.c
> @@ -1902,6 +1902,7 @@ static int event_read_fields(struct tep_event *event, struct tep_format_field **
>  
>  		*fields = field;
>  		fields = &field->next;
> +		field = NULL;
>  
>  	} while (1);
>
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index 8f4fb59..1ba2a78 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -1902,6 +1902,7 @@  static int event_read_fields(struct tep_event *event, struct tep_format_field **
 
 		*fields = field;
 		fields = &field->next;
+		field = NULL;
 
 	} while (1);