Skip to content

Commit 8cb62fe

Browse files
committed
inputflinger: Check for KeyCharacterMap before use
Fixes crash in InputReader: 10-09 23:27:30.342 F DEBUG : pid: 2243, tid: 2413, name: InputReader >>> system_server <<< 10-09 23:27:30.342 F DEBUG : uid: 1000 10-09 23:27:30.342 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) 10-09 23:27:30.342 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000040 10-09 23:27:30.342 F DEBUG : Cause: null pointer dereference Bug: 372558955 Test: Does not crash on input device without character map Flag: EXEMPT bugfix Change-Id: I0f4ada4663bdd51a233fa9c15eb2558db0081dd5
1 parent 5d649dc commit 8cb62fe

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

services/inputflinger/reader/EventHub.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,12 @@ bool EventHub::Device::hasKeycodeLocked(int keycode) const {
662662
if (hasKeycodeInternalLocked(keycode)) {
663663
return true;
664664
}
665-
666-
for (auto& fromKey : getKeyCharacterMap()->findKeyCodesMappedToKeyCode(keycode)) {
665+
// Check the key character map first. Not all input devices will have one.
666+
const std::shared_ptr<KeyCharacterMap> kcm = getKeyCharacterMap();
667+
if (kcm == nullptr) {
668+
return false;
669+
}
670+
for (auto& fromKey : kcm->findKeyCodesMappedToKeyCode(keycode)) {
667671
if (hasKeycodeInternalLocked(fromKey)) {
668672
return true;
669673
}

0 commit comments

Comments
 (0)