From 61f12e81657b4f0fb548f791e77786920bf3bb55 Mon Sep 17 00:00:00 2001 From: Martin Natano Date: Mon, 27 Jun 2022 20:10:52 +0200 Subject: [PATCH] Prevent out-of-bounds array access Fixes https://github.com/itgmania/itgmania/issues/27 --- src/arch/InputHandler/InputHandler_MacOSX_HID.mm | 2 +- src/archutils/Darwin/KeyboardDevice.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/arch/InputHandler/InputHandler_MacOSX_HID.mm b/src/arch/InputHandler/InputHandler_MacOSX_HID.mm index 56dc1f6c72..be296162cd 100644 --- a/src/arch/InputHandler/InputHandler_MacOSX_HID.mm +++ b/src/arch/InputHandler/InputHandler_MacOSX_HID.mm @@ -450,7 +450,7 @@ wchar_t InputHandler_MacOSX_HID::DeviceButtonToChar( DeviceButton button, bool b { CGEventRef event = CGEventCreate(nullptr); CGEventFlags mods = CGEventGetFlags(event); - CFRelease(event); + CFRelease(event); UInt32 nModifiers = bUseCurrentKeyModifiers ? (UInt32)mods : 0; wchar_t sCharCode = KeyCodeToChar( iMacVirtualKey, nModifiers ); if( sCharCode != 0 ) diff --git a/src/archutils/Darwin/KeyboardDevice.cpp b/src/archutils/Darwin/KeyboardDevice.cpp index 5db6f84b4d..46e8663e17 100644 --- a/src/archutils/Darwin/KeyboardDevice.cpp +++ b/src/archutils/Darwin/KeyboardDevice.cpp @@ -482,7 +482,14 @@ bool KeyboardDevice::DeviceButtonToMacVirtualKey( DeviceButton button, UInt8 &iM } bInited = true; } - iMacVKOut = g_iDeviceButtonToMacVirtualKey[button]; + if (button < sizeof(g_iDeviceButtonToMacVirtualKey)) + { + iMacVKOut = g_iDeviceButtonToMacVirtualKey[button]; + } + else + { + iMacVKOut = 0xFF; + } return iMacVKOut != 0xFF; }