Skip to content

Commit 8906d1d

Browse files
pirama-arumuga-nainarGerrit Code Review
authored andcommitted
Merge "inputflinger_tests: Fix asan error about new-delete type mismatch" into main
2 parents 412d19a + ee2f164 commit 8906d1d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8132,6 +8132,17 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) {
81328132
ASSERT_EQ(keyArgs.scanCode, verifiedKey.scanCode);
81338133
ASSERT_EQ(keyArgs.metaState, verifiedKey.metaState);
81348134
ASSERT_EQ(0, verifiedKey.repeatCount);
8135+
8136+
// InputEvent and subclasses don't have a virtual destructor and only
8137+
// InputEvent's destructor gets called when `verified` goes out of scope,
8138+
// even if `verifyInputEvent` returns an object of a subclass. To fix this,
8139+
// we should either consider using std::variant in some way, or introduce an
8140+
// intermediate POD data structure that we will put the data into just prior
8141+
// to signing. Adding virtual functions to these classes is undesirable as
8142+
// the bytes in these objects are getting signed. As a temporary fix, cast
8143+
// the pointer to the correct class (which is statically known) before
8144+
// destruction.
8145+
delete (VerifiedKeyEvent*)verified.release();
81358146
}
81368147

81378148
TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
@@ -8179,6 +8190,10 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
81798190
EXPECT_EQ(motionArgs.downTime, verifiedMotion.downTimeNanos);
81808191
EXPECT_EQ(motionArgs.metaState, verifiedMotion.metaState);
81818192
EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
8193+
8194+
// Cast to the correct type before destruction. See explanation at the end
8195+
// of the VerifyInputEvent_KeyEvent test.
8196+
delete (VerifiedMotionEvent*)verified.release();
81828197
}
81838198

81848199
/**

0 commit comments

Comments
 (0)