setupapi: Fix buffer size in SetupDiGetDeviceInterfaceDetailW.

This commit is contained in:
Christopher Berner 2008-03-26 21:38:53 -07:00 committed by Alexandre Julliard
parent 1bdd2ab628
commit 6bc8e9a116
2 changed files with 6 additions and 1 deletions

View File

@ -2971,7 +2971,7 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
} }
info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved; info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
if (info->symbolicLink) if (info->symbolicLink)
bytesNeeded += lstrlenW(info->symbolicLink); bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
if (DeviceInterfaceDetailDataSize >= bytesNeeded) if (DeviceInterfaceDetailDataSize >= bytesNeeded)
{ {
if (info->symbolicLink) if (info->symbolicLink)

View File

@ -627,6 +627,7 @@ static void testGetDeviceInterfaceDetail(void)
LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size); LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail = SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
(SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf; (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
DWORD expectedsize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
detail->cbSize = 0; detail->cbSize = 0;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
@ -656,6 +657,10 @@ static void testGetDeviceInterfaceDetail(void)
GetLastError()); GetLastError());
ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n", ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n",
detail->DevicePath); detail->DevicePath);
/* Check SetupDiGetDeviceInterfaceDetailW */
ret = SetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
ok(expectedsize == size, "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize: expected %d, got %d\n", expectedsize, size);
HeapFree(GetProcessHeap(), 0, buf); HeapFree(GetProcessHeap(), 0, buf);
} }
pSetupDiDestroyDeviceInfoList(set); pSetupDiDestroyDeviceInfoList(set);