Christopher Berner : setupapi: Fix buffer size in SetupDiGetDeviceInterfaceDetailW.

Alexandre Julliard julliard at winehq.org
Thu Mar 27 15:43:29 CDT 2008


Module: wine
Branch: master
Commit: 6bc8e9a11693f52d1f75dab0ac8df53a0d212adc
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6bc8e9a11693f52d1f75dab0ac8df53a0d212adc

Author: Christopher Berner <raccoonone at procyongames.com>
Date:   Wed Mar 26 21:38:53 2008 -0700

setupapi: Fix buffer size in SetupDiGetDeviceInterfaceDetailW.

---

 dlls/setupapi/devinst.c       |    2 +-
 dlls/setupapi/tests/devinst.c |    5 +++++
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index f7c3839..936f6a7 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -2971,7 +2971,7 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(
     }
     info = (struct InterfaceInfo *)DeviceInterfaceData->Reserved;
     if (info->symbolicLink)
-        bytesNeeded += lstrlenW(info->symbolicLink);
+        bytesNeeded += sizeof(WCHAR)*lstrlenW(info->symbolicLink);
     if (DeviceInterfaceDetailDataSize >= bytesNeeded)
     {
         if (info->symbolicLink)
diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c
index ef0d8d6..eb72408 100644
--- a/dlls/setupapi/tests/devinst.c
+++ b/dlls/setupapi/tests/devinst.c
@@ -627,6 +627,7 @@ static void testGetDeviceInterfaceDetail(void)
             LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
             SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
                 (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;
             SetLastError(0xdeadbeef);
@@ -656,6 +657,10 @@ static void testGetDeviceInterfaceDetail(void)
                     GetLastError());
             ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n",
                     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);
         }
         pSetupDiDestroyDeviceInfoList(set);




More information about the wine-cvs mailing list