Fix OOB read and UAF in InputDispatcher::flushSensor
In `InputDispatcher::flushSensor()`, erasing an element from
`mInboundQueue` returns an iterator that was unconditionally
incremented by the loop. If the erased element was the last one,
the increment advanced the iterator past `end()`, resulting in an
out-of-bounds read and use-after-free when the next iteration
dereferenced the invalid iterator.
This patch fixes the issue by updating the loop to only increment
the iterator when an element is not erased. Additionally, the
function now properly inspects the `SensorEntry` fields to ensure
only inbound sensor events matching the specified `deviceId` and
`sensorType` parameters are erased, whereas previously it was
unconditionally erasing all sensor events.
This change also includes additional fix in tests to make them
deterministic by freeze dispatching before the events are enqueued,
then add the events, and then call flush.
Test: atest inputflinger_tests --host
Bug: 514737201
Flag: EXEMPT BUGFIX
Low-Coverage-Reason: coverage infra is broken
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:321a057cca83b8a7843b394b644ed7ab9a24cefd
Cherrypicked by Aesir (go/aesir-backport-automation)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:806489cfc8926abfd25e56d09cbb780e08a0f662
Merged-In: I2b5e1ffd224864e20b0f86dce0aea9bf87a7dd8a
Change-Id: I2b5e1ffd224864e20b0f86dce0aea9bf87a7dd8a
5 files changed