Skip to content

Commit ff4a159

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

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
@@ -8101,6 +8101,17 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) {
81018101
ASSERT_EQ(keyArgs.scanCode, verifiedKey.scanCode);
81028102
ASSERT_EQ(keyArgs.metaState, verifiedKey.metaState);
81038103
ASSERT_EQ(0, verifiedKey.repeatCount);
8104+
8105+
// InputEvent and subclasses don't have a virtual destructor and only
8106+
// InputEvent's destructor gets called when `verified` goes out of scope,
8107+
// even if `verifyInputEvent` returns an object of a subclass. To fix this,
8108+
// we should either consider using std::variant in some way, or introduce an
8109+
// intermediate POD data structure that we will put the data into just prior
8110+
// to signing. Adding virtual functions to these classes is undesirable as
8111+
// the bytes in these objects are getting signed. As a temporary fix, cast
8112+
// the pointer to the correct class (which is statically known) before
8113+
// destruction.
8114+
delete (VerifiedKeyEvent*)verified.release();
81048115
}
81058116

81068117
TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
@@ -8148,6 +8159,10 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
81488159
EXPECT_EQ(motionArgs.downTime, verifiedMotion.downTimeNanos);
81498160
EXPECT_EQ(motionArgs.metaState, verifiedMotion.metaState);
81508161
EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
8162+
8163+
// Cast to the correct type before destruction. See explanation at the end
8164+
// of the VerifyInputEvent_KeyEvent test.
8165+
delete (VerifiedMotionEvent*)verified.release();
81518166
}
81528167

81538168
/**

0 commit comments

Comments
 (0)