Commit 8289c651 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

setupapi: Enforce a maximum device instance ID length.

parent c00a322d
......@@ -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;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment