From 405f673f7d3c1faac21acfa51f0121d9a9d473eb Mon Sep 17 00:00:00 2001 From: art-snake Date: Mon, 30 Sep 2024 21:17:05 +0300 Subject: [PATCH] fix use_of_uninitialized_value in message_loop_task_queues.cc (flutter/engine#55520) This issue was found with memory sanitizer. Commit 988c4ffb83398bf8511122d73f0f85010e0edeea introduced a change that leads to use-after-free condition. In function MessageLoopTaskQueues::GetNextTaskToRun: 1) Call is made to PeekNextTaskUnlocked(queue_id);. Returned value contains a reference to to an object of const DelayedTask& taken from an std::queue container as returned by primary_task_queue_.top(). 2) Variable TaskSource::TopTask top now contains a reference to this object. 3) Function queue_entries_.at(top.task_queue_id)->task_source->PopTask(...) which in turn calls pop() method on std::queue. 4) Object of type DelayedTask on top of the queue gets deleted. 5) top.task.GetTaskSourceGrade() is called later with top.task refering to an already deleted object. *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- engine/src/flutter/fml/message_loop_task_queues.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engine/src/flutter/fml/message_loop_task_queues.cc b/engine/src/flutter/fml/message_loop_task_queues.cc index bc017cc00c..f32fa7410a 100644 --- a/engine/src/flutter/fml/message_loop_task_queues.cc +++ b/engine/src/flutter/fml/message_loop_task_queues.cc @@ -132,9 +132,8 @@ fml::closure MessageLoopTaskQueues::GetNextTaskToRun(TaskQueueId queue_id, return nullptr; } fml::closure invocation = top.task.GetTask(); - queue_entries_.at(top.task_queue_id) - ->task_source->PopTask(top.task.GetTaskSourceGrade()); const auto task_source_grade = top.task.GetTaskSourceGrade(); + queue_entries_.at(top.task_queue_id)->task_source->PopTask(task_source_grade); tls_task_source_grade.reset(new TaskSourceGradeHolder{task_source_grade}); return invocation; }