Module: wine Branch: master Commit: 8289c651c04a4dbecad11199d206f2f82b849364 URL: https://source.winehq.org/git/wine.git/?a=commit;h=8289c651c04a4dbecad11199d...
Author: Zebediah Figura z.figura12@gmail.com Date: Tue Nov 27 19:55:34 2018 -0600
setupapi: Enforce a maximum device instance ID length.
Signed-off-by: Zebediah Figura z.figura12@gmail.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/setupapi/devinst.c | 14 +++++++++----- dlls/setupapi/tests/devinst.c | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 64c0413..8ce1344 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -1337,7 +1337,7 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da /*********************************************************************** * SetupDiCreateDeviceInfoA (SETUPAPI.@) */ -BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, PCSTR DeviceName, +BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name, const GUID *ClassGuid, PCSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags, PSP_DEVINFO_DATA DeviceInfoData) { @@ -1345,11 +1345,15 @@ BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, PCSTR DeviceName, LPWSTR DeviceNameW = NULL; LPWSTR DeviceDescriptionW = NULL;
- if (DeviceName) + if (!name || strlen(name) >= MAX_DEVICE_ID_LEN) { - DeviceNameW = MultiByteToUnicode(DeviceName, CP_ACP); - if (DeviceNameW == NULL) return FALSE; + SetLastError(ERROR_INVALID_DEVINST_NAME); + return FALSE; } + + DeviceNameW = MultiByteToUnicode(name, CP_ACP); + if (DeviceNameW == NULL) return FALSE; + if (DeviceDescription) { DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP); @@ -1407,7 +1411,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, PCWSTR DeviceName, devinfo, debugstr_w(DeviceName), debugstr_guid(ClassGuid), debugstr_w(DeviceDescription), hwndParent, CreationFlags, device_data);
- if (!DeviceName) + if (!DeviceName || strlenW(DeviceName) >= MAX_DEVICE_ID_LEN) { SetLastError(ERROR_INVALID_DEVINST_NAME); return FALSE; diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index 0e6a1c0..338393e 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -271,8 +271,8 @@ static void test_device_info(void) { static const GUID deadbeef = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}}; SP_DEVINFO_DATA device = {0}, ret_device = {sizeof(ret_device)}; + char id[MAX_DEVICE_ID_LEN + 2]; HDEVINFO set; - char id[50]; BOOL ret;
SetLastError(0xdeadbeef); @@ -382,6 +382,24 @@ todo_wine { check_device_info(set, 2, &guid, "ROOT\LEGACY_BOGUS\testguid"); check_device_info(set, 3, NULL, NULL);
+ memset(id, 'x', sizeof(id)); + memcpy(id, "Root\LEGACY_BOGUS\", strlen("Root\LEGACY_BOGUS\")); + id[MAX_DEVICE_ID_LEN + 1] = 0; + SetLastError(0xdeadbeef); + ret = SetupDiCreateDeviceInfoA(set, id, &guid, NULL, NULL, 0, NULL); + ok(!ret, "Expected failure.\n"); + ok(GetLastError() == ERROR_INVALID_DEVINST_NAME, "Got unexpected error %#x.\n", GetLastError()); + + id[MAX_DEVICE_ID_LEN] = 0; + SetLastError(0xdeadbeef); + ret = SetupDiCreateDeviceInfoA(set, id, &guid, NULL, NULL, 0, NULL); + ok(!ret, "Expected failure.\n"); + ok(GetLastError() == ERROR_INVALID_DEVINST_NAME, "Got unexpected error %#x.\n", GetLastError()); + + id[MAX_DEVICE_ID_LEN - 1] = 0; + ret = SetupDiCreateDeviceInfoA(set, id, &guid, NULL, NULL, 0, NULL); + ok(ret, "Failed to create device, error %#x.\n", GetLastError()); + SetupDiDestroyDeviceInfoList(set); }