Skip to content

Commit 575754d

Browse files
authored
Fix x11 undefined behavior (#18323)
* Fix an OOB memory access in x11 input if >16 devices It looks like the mouse device list was meant to be initialized with -1, but the mouse device list should contain only up to `j` values where j is the number of actual mice. * Also make sure j stays under max mouse idx This is just to be safe in case we have... more than 16 master pointers
1 parent 044c9f8 commit 575754d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

input/drivers/x11_input.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ static void *x_input_init(const char *joypad_driver)
9696
input_keymaps_init_keyboard_lut(rarch_key_map_x11);
9797

9898
#ifdef HAVE_XI2
99+
for (i = 0; i < MAX_MOUSE_IDX; i++)
100+
x11->mouse_dev_list[i] = -1;
99101
x11->di = XIQueryDevice(x11->display, XIAllDevices, &cnt);
100-
for (i = 0; i < cnt; i++)
102+
for (i = 0; i < cnt && j < MAX_MOUSE_IDX; i++)
101103
{
102-
x11->mouse_dev_list[i] = -1;
103104
dev = &(x11->di[i]);
104105
RARCH_DBG("[X11] Device detected, %d \"%s\" attached to %d.\n", i, dev->name, dev->attachment);
105106
if (dev->use == XIMasterPointer)

0 commit comments

Comments
 (0)