Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WINTERMUTE: Check keyboard state array index
vKeyToKeyCode() method was unsafe if vkey >= KEYSTATES_ARRAY_SIZE was
provided, fixed
  • Loading branch information
lolbot-iichan committed Aug 18, 2018
1 parent 9f01f76 commit 0e15c05
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions engines/wintermute/base/base_keyboard_state.cpp
Expand Up @@ -32,6 +32,8 @@
#include "common/system.h" #include "common/system.h"
#include "common/keyboard.h" #include "common/keyboard.h"


#define KEYSTATES_ARRAY_SIZE (Common::KEYCODE_UNDO + 1) // Hardcoded size for the common/keyboard.h enum

namespace Wintermute { namespace Wintermute {


IMPLEMENT_PERSISTENT(BaseKeyboardState, false) IMPLEMENT_PERSISTENT(BaseKeyboardState, false)
Expand All @@ -46,8 +48,8 @@ BaseKeyboardState::BaseKeyboardState(BaseGame *inGame) : BaseScriptable(inGame)
_currentAlt = false; _currentAlt = false;
_currentControl = false; _currentControl = false;


_keyStates = new uint8[323]; // Hardcoded size for the common/keyboard.h enum _keyStates = new uint8[KEYSTATES_ARRAY_SIZE];
for (int i = 0; i < 323; i++) { for (int i = 0; i < KEYSTATES_ARRAY_SIZE; i++) {
_keyStates[i] = false; _keyStates[i] = false;
} }
} }
Expand Down Expand Up @@ -499,7 +501,7 @@ Common::KeyCode BaseKeyboardState::vKeyToKeyCode(uint32 vkey) {
return Common::KEYCODE_SCROLLOCK; return Common::KEYCODE_SCROLLOCK;
default: default:
warning("Unknown VKEY: %d", vkey); warning("Unknown VKEY: %d", vkey);
return (Common::KeyCode)vkey; return (Common::KeyCode)(vkey < KEYSTATES_ARRAY_SIZE ? vkey : 0);
break; break;
} }


Expand Down

0 comments on commit 0e15c05

Please sign in to comment.