Fix out-of-bounds access in XWindowsScreen::updateButtons

This code triggers an assertion in gcc's std_vector.h on my system due
to a logical button 0 causing a write to m_buttons[-1], and a SIGABRT.

I've tried to make this code do what it seems to be intended to do, but
m_buttons isn't actually read from anywhere anyway.
This commit is contained in:
Jake Barnes 2022-11-06 17:05:14 +11:00
parent 653e4badeb
commit 9cfd521ae1
No known key found for this signature in database
GPG Key ID: 4D161C7487F18303
2 changed files with 5 additions and 5 deletions

View File

@ -1941,15 +1941,15 @@ XWindowsScreen::updateButtons()
} }
// allocate button array // allocate button array
m_buttons.resize(maxButton); m_buttons.resize(maxButton + 1);
// fill in button array values. m_buttons[i] is the physical // fill in button array values. m_buttons[i] is the physical
// button number for logical button i+1. // button number for logical button i.
for (UInt32 i = 0; i < numButtons; ++i) { for (UInt32 i = 0; i < maxButton + 1; ++i) {
m_buttons[i] = 0; m_buttons[i] = 0;
} }
for (UInt32 i = 0; i < numButtons; ++i) { for (UInt32 i = 0; i < numButtons; ++i) {
m_buttons[tmpButtons[i] - 1] = i + 1; m_buttons[tmpButtons[i]] = i;
} }
// clean up // clean up

View File

@ -228,7 +228,7 @@ private:
bool m_screensaverNotify; bool m_screensaverNotify;
// logical to physical button mapping. m_buttons[i] gives the // logical to physical button mapping. m_buttons[i] gives the
// physical button for logical button i+1. // physical button for logical button i.
std::vector<unsigned char> m_buttons; std::vector<unsigned char> m_buttons;
// true if global auto-repeat was enabled before we turned it off // true if global auto-repeat was enabled before we turned it off