Skip to content

Commit 04023f3

Browse files
Merge "inputflinger_tests: Fix asan error about new-delete type mismatch" into main am: 8906d1d
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3466200 Change-Id: Id5ed3c362495944075daf91a7a59e948b9a07d0a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents 368766b + 8906d1d commit 04023f3

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)