From 8d763b7f0df0218c2a7d378a0b094cc51851ef0f Mon Sep 17 00:00:00 2001 From: Kyle Ambroff-Kao Date: Mon, 20 Jan 2020 17:33:10 -0800 Subject: [PATCH] Terminal: Fix crash for keystroke with unexpected modifiers This patch fixes a segfault in Terminal that happens when you issue a keystroke with unexpected modifiers. An easy way to repro this is: 1. Set command key to super 2. Set option key to meta in Terminal 3. Issue `ctrl+alt+shift+` In DefaultState::KeyDown(), the branch that handles option key as meta detects that additional modifiers were used along with the meta key and tries to look up the keymap associated with that combination of modifier keys. This lookup in TermView::fKeymapTableForModifierse can return NULL, since TermView::SetKeymap() sets a pre-defined set of (modifier combo) => keymap entries. Change-Id: I3ce4a7cff6c84913d99507e44849f9b048769f67 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2138 Reviewed-by: waddlesplash --- src/apps/terminal/TermViewStates.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/terminal/TermViewStates.cpp b/src/apps/terminal/TermViewStates.cpp index 5aab892159..2cd4dc5020 100644 --- a/src/apps/terminal/TermViewStates.cpp +++ b/src/apps/terminal/TermViewStates.cpp @@ -218,12 +218,13 @@ TermView::DefaultState::KeyDown(const char* bytes, int32 numBytes) // Determine the character produced by the same keypress without the // Option key mod &= B_SHIFT_KEY | B_CAPS_LOCK | B_CONTROL_KEY; - if (mod == 0) { + const int32 (*keymapTable)[128] = (mod == 0) + ? NULL + : fView->fKeymapTableForModifiers.Get(mod); + if (keymapTable == NULL) { bytes = (const char*)&rawChar; numBytes = 1; } else { - const int32 (*keymapTable)[128] = - fView->fKeymapTableForModifiers.Get(mod); bytes = &fView->fKeymapChars[(*keymapTable)[key]]; numBytes = *(bytes++); }