libtraceevent: Reset field properly in event_read_fields()
PATCH 1/1 libtraceevent: Reset field properly in event_read_fields()
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.
--- src/event-parse.c | 1 + 1 file changed, 1 insertion(+)
src/event-parse.c +1 -0
@@ -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 );
Signature · 1 line
2.36.1.255.ge46751e96f-goog
Steven Rostedt
AppliedQuoted 10 lines · On Mon, 6 Jun 2022 21:59:25 -0700 Namhyung Kim <[email protected]> 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.
Quoted 3 lines
This was found by a fuzz test with an event having only one field.
Signed-off-by Namhyung Kim <[email protected]>
Applied. Thanks Namhyung!
-- Steve
Quoted 16 lines
--- src/event-parse.c | 1 + 1 file changed, 1 insertion(+)src/event-parse.c +1
-0@@ -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 );