setupapi/devinst: Struct size passed needs to be exact.

This commit is contained in:
Paul Vriens 2008-02-25 20:19:53 +01:00 committed by Alexandre Julliard
parent d91f3a93ae
commit 433ca7d8bd
2 changed files with 11 additions and 3 deletions

View File

@ -2885,9 +2885,8 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize <
offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char) ||
DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A)))
if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize !=
offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char)))
{
SetLastError(ERROR_INVALID_USER_BUFFER);
return FALSE;

View File

@ -641,6 +641,15 @@ static void testGetDeviceInterfaceDetail(void)
ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
"Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
SetLastError(0xdeadbeef);
ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
size, &size, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
"Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
/* Windows 2000 and up check for the exact size. Win9x returns ERROR_INVALID_PARAMETER
* on every call (so doesn't get here) and NT4 doesn't have this function.
*/
detail->cbSize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char);
ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
size, &size, NULL);
ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",