From: Aric Stewart aric@codeweavers.com
If rawinput_from_hardware_message generates an error then the number of packets handled may be less then the size of the buffer. Correctly report only the successfully processed packets to avoid using uninitialized data. --- dlls/win32u/rawinput.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/dlls/win32u/rawinput.c b/dlls/win32u/rawinput.c index 8795ebbba00..585eea9f3e1 100644 --- a/dlls/win32u/rawinput.c +++ b/dlls/win32u/rawinput.c @@ -609,7 +609,7 @@ UINT WINAPI NtUserGetRawInputDeviceInfo( HANDLE handle, UINT command, void *data */ UINT WINAPI NtUserGetRawInputBuffer( RAWINPUT *data, UINT *data_size, UINT header_size ) { - unsigned int count = 0, remaining, rawinput_size, next_size, overhead; + unsigned int count = 0, remaining, rawinput_size, next_size, overhead, handled; struct rawinput_thread_data *thread_data; struct hardware_msg_data *msg_data; RAWINPUT *rawinput; @@ -665,6 +665,7 @@ UINT WINAPI NtUserGetRawInputBuffer( RAWINPUT *data, UINT *data_size, UINT heade SERVER_END_REQ;
remaining = *data_size; + handled = 0; for (i = 0; i < count; ++i) { data->header.dwSize = remaining; @@ -678,11 +679,12 @@ UINT WINAPI NtUserGetRawInputBuffer( RAWINPUT *data, UINT *data_size, UINT heade remaining -= data->header.dwSize; data = NEXTRAWINPUTBLOCK(data); msg_data = (struct hardware_msg_data *)((char *)msg_data + msg_data->size); + handled++; }
if (!next_size) { - if (!count) + if (!handled) *data_size = 0; else next_size = rawinput_size; @@ -692,12 +694,12 @@ UINT WINAPI NtUserGetRawInputBuffer( RAWINPUT *data, UINT *data_size, UINT heade { RtlSetLastWin32Error( ERROR_INSUFFICIENT_BUFFER ); *data_size = next_size; - count = ~0u; + handled = count = ~0u; }
- TRACE( "data %p, data_size %p (%u), header_size %u, count %u\n", - data, data_size, *data_size, header_size, count ); - return count; + TRACE( "data %p, data_size %p (%u), header_size %u, count %u(%u)\n", + data, data_size, *data_size, header_size, count, handled ); + return handled; }
/**********************************************************************