mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-27 02:46:08 +08:00
Fixed potential uninitialized memory access (thanks Mathieu!)
GetRawInputDeviceList() can return a different number of devices than was allocated. Fixes https://github.com/libsdl-org/SDL/issues/2759 (cherry picked from commitb9784feb24) (cherry picked from commitaa129c9257)
This commit is contained in:
@@ -988,7 +988,8 @@ static void RAWINPUT_DetectDevices(void)
|
|||||||
|
|
||||||
devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * device_count);
|
devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * device_count);
|
||||||
if (devices) {
|
if (devices) {
|
||||||
if (GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST)) != -1) {
|
device_count = GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST));
|
||||||
|
if (device_count != (UINT)-1) {
|
||||||
for (i = 0; i < device_count; ++i) {
|
for (i = 0; i < device_count; ++i) {
|
||||||
RAWINPUT_AddDevice(devices[i].hDevice);
|
RAWINPUT_AddDevice(devices[i].hDevice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,8 @@ static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
|||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetRawInputDeviceList(raw_devices, &raw_device_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
|
raw_device_count = GetRawInputDeviceList(raw_devices, &raw_device_count, sizeof(RAWINPUTDEVICELIST));
|
||||||
|
if (raw_device_count == (UINT)-1) {
|
||||||
SDL_free(raw_devices);
|
SDL_free(raw_devices);
|
||||||
raw_devices = NULL;
|
raw_devices = NULL;
|
||||||
return SDL_FALSE; /* oh well. */
|
return SDL_FALSE; /* oh well. */
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ static void GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
|
device_count = GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST));
|
||||||
|
if (device_count == (UINT)-1) {
|
||||||
SDL_free(devices);
|
SDL_free(devices);
|
||||||
return; /* oh well. */
|
return; /* oh well. */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user