Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 385 ++++++++++++------------------------------------ 1 file changed, 95 insertions(+), 290 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 771fc70395..630d3e9587 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -129,6 +129,34 @@ struct device_iface struct list entry; };
+static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data) +{ + struct DeviceInfoSet *set = devinfo; + struct device *device; + + if (!devinfo || devinfo == INVALID_HANDLE_VALUE || set->magic != SETUP_DEVICE_INFO_SET_MAGIC) + { + SetLastError(ERROR_INVALID_HANDLE); + return NULL; + } + + if (!data || data->cbSize != sizeof(*data) || !data->Reserved) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + device = (struct device *)data->Reserved; + + if (device->set != set) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + return device; +} + static inline void copy_device_data(SP_DEVINFO_DATA *data, const struct device *device) { data->ClassGuid = device->class; @@ -1233,44 +1261,18 @@ HKEY WINAPI SetupDiCreateDevRegKeyA( /*********************************************************************** * SetupDiCreateDevRegKeyW (SETUPAPI.@) */ -HKEY WINAPI SetupDiCreateDevRegKeyW( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Scope, - DWORD HwProfile, - DWORD KeyType, - HINF InfHandle, - PCWSTR InfSectionName) +HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, DWORD Scope, + DWORD HwProfile, DWORD KeyType, HINF InfHandle, const WCHAR *InfSectionName) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device; HKEY key = INVALID_HANDLE_VALUE;
- TRACE("%p %p %d %d %d %p %s\n", DeviceInfoSet, DeviceInfoData, Scope, - HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName)); + TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, inf_handle %p, inf_section %s.\n", + devinfo, device_data, Scope, HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName));
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return INVALID_HANDLE_VALUE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return INVALID_HANDLE_VALUE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return INVALID_HANDLE_VALUE; - } - device = (struct device *)DeviceInfoData->Reserved; - if (device->set != set) - { - SetLastError(ERROR_INVALID_PARAMETER); - return INVALID_HANDLE_VALUE; - } + if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC) { SetLastError(ERROR_INVALID_FLAGS); @@ -1301,8 +1303,7 @@ HKEY WINAPI SetupDiCreateDevRegKeyW( } if (InfHandle) SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL, - NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, DeviceInfoSet, - DeviceInfoData); + NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, devinfo, device_data); return key; }
@@ -1497,42 +1498,17 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet, PCWSTR DeviceName, /*********************************************************************** * SetupDiRegisterDeviceInfo (SETUPAPI.@) */ -BOOL WINAPI SetupDiRegisterDeviceInfo( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Flags, - PSP_DETSIG_CMPPROC CompareProc, - PVOID CompareContext, - PSP_DEVINFO_DATA DupDeviceInfoData) +BOOL WINAPI SetupDiRegisterDeviceInfo(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, DWORD flags, + PSP_DETSIG_CMPPROC compare_proc, void *context, SP_DEVINFO_DATA *duplicate_data) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device;
- TRACE("%p %p %08x %p %p %p\n", DeviceInfoSet, DeviceInfoData, Flags, - CompareProc, CompareContext, DupDeviceInfoData); + TRACE("devinfo %p, data %p, flags %#x, compare_proc %p, context %p, duplicate_data %p.\n", + devinfo, device_data, flags, compare_proc, context, duplicate_data);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - device = (struct device *)DeviceInfoData->Reserved; - if (device->set != set) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + if (device->phantom) { device->phantom = FALSE; @@ -1675,41 +1651,17 @@ BOOL WINAPI SetupDiGetDeviceInstanceIdA( /*********************************************************************** * SetupDiGetDeviceInstanceIdW (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceInstanceIdW( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - PWSTR DeviceInstanceId, - DWORD DeviceInstanceIdSize, - PDWORD RequiredSize) +BOOL WINAPI SetupDiGetDeviceInstanceIdW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, + WCHAR *DeviceInstanceId, DWORD DeviceInstanceIdSize, DWORD *RequiredSize) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device;
- TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId, - DeviceInstanceIdSize, RequiredSize); + TRACE("devinfo %p, device_data %p, DeviceInstanceId %p, DeviceInstanceIdSize %d, RequiredSize %p.\n", + devinfo, device_data, DeviceInstanceId, DeviceInstanceIdSize, RequiredSize);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - device = (struct device *)DeviceInfoData->Reserved; - if (device->set != set) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + TRACE("instance ID: %s\n", debugstr_w(device->instanceId)); if (DeviceInstanceIdSize < strlenW(device->instanceId) + 1) { @@ -2466,51 +2418,25 @@ BOOL WINAPI SetupDiCreateDeviceInterfaceA( /*********************************************************************** * SetupDiCreateDeviceInterfaceW (SETUPAPI.@) */ -BOOL WINAPI SetupDiCreateDeviceInterfaceW( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - const GUID *InterfaceClassGuid, - PCWSTR ReferenceString, - DWORD CreationFlags, - SP_DEVICE_INTERFACE_DATA *iface_data) +BOOL WINAPI SetupDiCreateDeviceInterfaceW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, + const GUID *class, const WCHAR *refstr, DWORD flags, SP_DEVICE_INTERFACE_DATA *iface_data) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device; struct device_iface *iface;
- TRACE("%p %p %s %s %08x %p\n", DeviceInfoSet, DeviceInfoData, - debugstr_guid(InterfaceClassGuid), debugstr_w(ReferenceString), - CreationFlags, iface_data); + TRACE("devinfo %p, device_data %p, class %s, refstr %s, flags %#x, iface_data %p.\n", + devinfo, device_data, debugstr_guid(class), debugstr_w(refstr), flags, iface_data);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - device = (struct device *)DeviceInfoData->Reserved; - if (device->set != set) - { - SetLastError(ERROR_INVALID_PARAMETER); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - if (!InterfaceClassGuid) + + if (!class) { SetLastError(ERROR_INVALID_USER_BUFFER); return FALSE; } - if (!(iface = SETUPDI_CreateDeviceInterface(device, InterfaceClassGuid, - ReferenceString))) + + if (!(iface = SETUPDI_CreateDeviceInterface(device, class, refstr))) return FALSE;
if (iface_data) @@ -2960,45 +2886,25 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailW( /*********************************************************************** * SetupDiGetDeviceRegistryPropertyA (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceRegistryPropertyA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize) +BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(HDEVINFO devinfo, + SP_DEVINFO_DATA *device_data, DWORD Property, DWORD *PropertyRegDataType, + BYTE *PropertyBuffer, DWORD PropertyBufferSize, DWORD *RequiredSize) { BOOL ret = FALSE; - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device;
- TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, - Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, - RequiredSize); + TRACE("devinfo %p, device_data %p, property %d, type %p, buffer %p, size %d, required %p\n", + devinfo, device_data, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } + if (PropertyBufferSize && PropertyBuffer == NULL) { SetLastError(ERROR_INVALID_DATA); return FALSE; } - device = (struct device *)DeviceInfoData->Reserved; + if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameA) { DWORD size = PropertyBufferSize; @@ -3022,45 +2928,25 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyA( /*********************************************************************** * SetupDiGetDeviceRegistryPropertyW (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceRegistryPropertyW( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize) +BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO devinfo, + SP_DEVINFO_DATA *device_data, DWORD Property, DWORD *PropertyRegDataType, + BYTE *PropertyBuffer, DWORD PropertyBufferSize, DWORD *RequiredSize) { BOOL ret = FALSE; - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device;
- TRACE("%p %p %d %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, - Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, - RequiredSize); + TRACE("devinfo %p, device_data %p, prop %d, type %p, buffer %p, size %d, required %p\n", + devinfo, device_data, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + if (PropertyBufferSize && PropertyBuffer == NULL) { SetLastError(ERROR_INVALID_DATA); return FALSE; } - device = (struct device *)DeviceInfoData->Reserved; + if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameW) { DWORD size = PropertyBufferSize; @@ -3084,37 +2970,18 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyW( /*********************************************************************** * SetupDiSetDeviceRegistryPropertyA (SETUPAPI.@) */ -BOOL WINAPI SetupDiSetDeviceRegistryPropertyA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - const BYTE *PropertyBuffer, - DWORD PropertyBufferSize) +BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, + DWORD Property, const BYTE *PropertyBuffer, DWORD PropertyBufferSize) { BOOL ret = FALSE; - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device;
- TRACE("%p %p %d %p %d\n", DeviceInfoSet, DeviceInfoData, Property, - PropertyBuffer, PropertyBufferSize); + TRACE("devinfo %p, device_data %p, prop %d, buffer %p, size %d.\n", + devinfo, device_data, Property, PropertyBuffer, PropertyBufferSize);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - device = (struct device *)DeviceInfoData->Reserved; + if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameA) { LONG l = RegSetValueExA(device->key, PropertyMap[Property].nameA, 0, @@ -3134,29 +3001,14 @@ BOOL WINAPI SetupDiSetDeviceRegistryPropertyA( BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, DWORD prop, const BYTE *buffer, DWORD size) { - struct DeviceInfoSet *set = devinfo; struct device *device;
- TRACE("%p %p %d %p %d\n", devinfo, device_data, prop, buffer, size); + TRACE("devinfo %p, device_data %p, prop %d, buffer %p, size %d.\n", + devinfo, device_data, prop, buffer, size);
- if (!devinfo || devinfo == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - if (!device_data || device_data->cbSize != sizeof(SP_DEVINFO_DATA) - || !device_data->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - }
- device = (struct device *)device_data->Reserved; return SETUPDI_SetDeviceRegistryPropertyW(device, prop, buffer, size); }
@@ -3649,37 +3501,18 @@ static HKEY SETUPDI_OpenDrvKey(struct device *device, REGSAM samDesired) /*********************************************************************** * SetupDiOpenDevRegKey (SETUPAPI.@) */ -HKEY WINAPI SetupDiOpenDevRegKey( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Scope, - DWORD HwProfile, - DWORD KeyType, - REGSAM samDesired) +HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, + DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device; HKEY key = INVALID_HANDLE_VALUE;
- TRACE("%p %p %d %d %d %x\n", DeviceInfoSet, DeviceInfoData, - Scope, HwProfile, KeyType, samDesired); + TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, access %#x.\n", + devinfo, device_data, Scope, HwProfile, KeyType, samDesired);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return INVALID_HANDLE_VALUE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return INVALID_HANDLE_VALUE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return INVALID_HANDLE_VALUE; - } + if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC) { SetLastError(ERROR_INVALID_FLAGS); @@ -3690,12 +3523,7 @@ HKEY WINAPI SetupDiOpenDevRegKey( SetLastError(ERROR_INVALID_FLAGS); return INVALID_HANDLE_VALUE; } - device = (struct device *)DeviceInfoData->Reserved; - if (device->set != set) - { - SetLastError(ERROR_INVALID_PARAMETER); - return INVALID_HANDLE_VALUE; - } + if (device->phantom) { SetLastError(ERROR_DEVINFO_NOT_REGISTERED); @@ -3766,36 +3594,18 @@ static BOOL SETUPDI_DeleteDrvKey(struct device *device) /*********************************************************************** * SetupDiDeleteDevRegKey (SETUPAPI.@) */ -BOOL WINAPI SetupDiDeleteDevRegKey( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Scope, - DWORD HwProfile, - DWORD KeyType) +BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, + DWORD Scope, DWORD HwProfile, DWORD KeyType) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device *device; BOOL ret = FALSE;
- TRACE("%p %p %d %d %d\n", DeviceInfoSet, DeviceInfoData, Scope, HwProfile, - KeyType); + TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d.\n", + devinfo, device_data, Scope, HwProfile, KeyType);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(device = get_device(devinfo, device_data))) return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) - || !DeviceInfoData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + if (Scope != DICS_FLAG_GLOBAL && Scope != DICS_FLAG_CONFIGSPECIFIC) { SetLastError(ERROR_INVALID_FLAGS); @@ -3806,12 +3616,7 @@ BOOL WINAPI SetupDiDeleteDevRegKey( SetLastError(ERROR_INVALID_FLAGS); return FALSE; } - device = (struct device *)DeviceInfoData->Reserved; - if (device->set != set) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + if (device->phantom) { SetLastError(ERROR_DEVINFO_NOT_REGISTERED);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 121 +++++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 78 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 630d3e9587..69f6fa2fe8 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -157,6 +157,25 @@ static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data) return device; }
+static struct device_iface *get_device_iface(HDEVINFO devinfo, const SP_DEVICE_INTERFACE_DATA *data) +{ + struct DeviceInfoSet *set = devinfo; + + if (!devinfo || devinfo == INVALID_HANDLE_VALUE || set->magic != SETUP_DEVICE_INFO_SET_MAGIC) + { + SetLastError(ERROR_INVALID_HANDLE); + return NULL; + } + + if (!data || data->cbSize != sizeof(*data) || !data->Reserved) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + return (struct device_iface *)data->Reserved; +} + static inline void copy_device_data(SP_DEVINFO_DATA *data, const struct device *device) { data->ClassGuid = device->class; @@ -2493,34 +2512,22 @@ HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data, DWORD reserved, REGSAM access, HINF hinf, const WCHAR *section) { - struct DeviceInfoSet *set = devinfo; struct device_iface *iface; HKEY refstr_key, params_key; WCHAR *path; LONG ret;
- TRACE("%p %p %d %#x %p %s\n", devinfo, iface_data, reserved, access, hinf, - debugstr_w(section)); + TRACE("devinfo %p, iface_data %p, reserved %d, access %#x, hinf %p, section %s.\n", + devinfo, iface_data, reserved, access, hinf, debugstr_w(section)); + + if (!(iface = get_device_iface(devinfo, iface_data)))
- if (!devinfo || devinfo == INVALID_HANDLE_VALUE || - set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return INVALID_HANDLE_VALUE; - } - if (!iface_data || iface_data->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) || - !iface_data->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return INVALID_HANDLE_VALUE; - } if (hinf && !section) { SetLastError(ERROR_INVALID_PARAMETER); return INVALID_HANDLE_VALUE; }
- iface = (struct device_iface *)iface_data->Reserved; if (!(path = get_refstr_key_path(iface))) { SetLastError(ERROR_OUTOFMEMORY); @@ -2554,28 +2561,16 @@ HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO devinfo, BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data, DWORD reserved) { - struct DeviceInfoSet *set = devinfo; struct device_iface *iface; HKEY refstr_key; WCHAR *path; LONG ret;
- TRACE("%p %p %d\n", devinfo, iface_data, reserved); + TRACE("devinfo %p, iface_data %p, reserved %d.\n", devinfo, iface_data, reserved);
- if (!devinfo || devinfo == INVALID_HANDLE_VALUE || - set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!iface_data || iface_data->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) || - !iface_data->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); + if (!(iface = get_device_iface(devinfo, iface_data))) return FALSE; - }
- iface = (struct device_iface *)iface_data->Reserved; if (!(path = get_refstr_key_path(iface))) { SetLastError(ERROR_OUTOFMEMORY); @@ -2743,36 +2738,21 @@ BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo) /*********************************************************************** * SetupDiGetDeviceInterfaceDetailA (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceInterfaceDetailA( - HDEVINFO DeviceInfoSet, - PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, - PSP_DEVICE_INTERFACE_DETAIL_DATA_A DeviceInterfaceDetailData, - DWORD DeviceInterfaceDetailDataSize, - PDWORD RequiredSize, - SP_DEVINFO_DATA *device_data) +BOOL WINAPI SetupDiGetDeviceInterfaceDetailA(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data, + SP_DEVICE_INTERFACE_DETAIL_DATA_A *DeviceInterfaceDetailData, + DWORD DeviceInterfaceDetailDataSize, DWORD *RequiredSize, SP_DEVINFO_DATA *device_data) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device_iface *iface; DWORD bytesNeeded = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]); BOOL ret = FALSE;
- TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet, - DeviceInterfaceData, DeviceInterfaceDetailData, - DeviceInterfaceDetailDataSize, RequiredSize, device_data); + TRACE("devinfo %p, iface_data %p, detail_data %p, size %d, needed %p, device_data %p.\n", + devinfo, iface_data, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, + RequiredSize, device_data);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE || - set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!DeviceInterfaceData || - DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) || - !DeviceInterfaceData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); + if (!(iface = get_device_iface(devinfo, iface_data))) return FALSE; - } + if (DeviceInterfaceDetailData && DeviceInterfaceDetailData->cbSize != sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A)) { @@ -2784,7 +2764,7 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailA( SetLastError(ERROR_INVALID_USER_BUFFER); return FALSE; } - iface = (struct device_iface *)DeviceInterfaceData->Reserved; + if (iface->symlink) bytesNeeded += WideCharToMultiByte(CP_ACP, 0, iface->symlink, -1, NULL, 0, NULL, NULL); @@ -2816,37 +2796,22 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailA( /*********************************************************************** * SetupDiGetDeviceInterfaceDetailW (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceInterfaceDetailW( - HDEVINFO DeviceInfoSet, - PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, - PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, - DWORD DeviceInterfaceDetailDataSize, - PDWORD RequiredSize, - SP_DEVINFO_DATA *device_data) +BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *iface_data, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *DeviceInterfaceDetailData, + DWORD DeviceInterfaceDetailDataSize, DWORD *RequiredSize, SP_DEVINFO_DATA *device_data) { - struct DeviceInfoSet *set = DeviceInfoSet; struct device_iface *iface; DWORD bytesNeeded = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR); /* include NULL terminator */ BOOL ret = FALSE;
- TRACE("(%p, %p, %p, %d, %p, %p)\n", DeviceInfoSet, - DeviceInterfaceData, DeviceInterfaceDetailData, - DeviceInterfaceDetailDataSize, RequiredSize, device_data); + TRACE("devinfo %p, iface_data %p, detail_data %p, size %d, needed %p, device_data %p.\n", + devinfo, iface_data, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, + RequiredSize, device_data);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE || - set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(iface = get_device_iface(devinfo, iface_data))) return FALSE; - } - if (!DeviceInterfaceData || - DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) || - !DeviceInterfaceData->Reserved) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + if (DeviceInterfaceDetailData && (DeviceInterfaceDetailData->cbSize < offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR) || DeviceInterfaceDetailData->cbSize > sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W))) @@ -2859,7 +2824,7 @@ BOOL WINAPI SetupDiGetDeviceInterfaceDetailW( SetLastError(ERROR_INVALID_USER_BUFFER); return FALSE; } - iface = (struct device_iface *)DeviceInterfaceData->Reserved; + if (iface->symlink) bytesNeeded += sizeof(WCHAR) * lstrlenW(iface->symlink); if (DeviceInterfaceDetailDataSize >= bytesNeeded)
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 203 +++++++++++++++++++----------------------------- 1 file changed, 79 insertions(+), 124 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 69f6fa2fe8..1f020b9b8e 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -129,10 +129,9 @@ struct device_iface struct list entry; };
-static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data) +static struct DeviceInfoSet *get_device_set(HDEVINFO devinfo) { struct DeviceInfoSet *set = devinfo; - struct device *device;
if (!devinfo || devinfo == INVALID_HANDLE_VALUE || set->magic != SETUP_DEVICE_INFO_SET_MAGIC) { @@ -140,6 +139,17 @@ static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data) return NULL; }
+ return set; +} + +static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data) +{ + struct DeviceInfoSet *set; + struct device *device; + + if (!(set = get_device_set(devinfo))) + return FALSE; + if (!data || data->cbSize != sizeof(*data) || !data->Reserved) { SetLastError(ERROR_INVALID_PARAMETER); @@ -159,13 +169,8 @@ static struct device *get_device(HDEVINFO devinfo, const SP_DEVINFO_DATA *data)
static struct device_iface *get_device_iface(HDEVINFO devinfo, const SP_DEVICE_INTERFACE_DATA *data) { - struct DeviceInfoSet *set = devinfo; - - if (!devinfo || devinfo == INVALID_HANDLE_VALUE || set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return NULL; - } + if (!get_device_set(devinfo)) + return FALSE;
if (!data || data->cbSize != sizeof(*data) || !data->Reserved) { @@ -1387,38 +1392,33 @@ static DWORD SETUPDI_DevNameToDevID(LPCWSTR devName) /*********************************************************************** * SetupDiCreateDeviceInfoW (SETUPAPI.@) */ -BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet, PCWSTR DeviceName, +BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, PCWSTR DeviceName, const GUID *ClassGuid, PCWSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags, SP_DEVINFO_DATA *device_data) { - struct DeviceInfoSet *set = DeviceInfoSet; + struct DeviceInfoSet *set; BOOL ret = FALSE, allocatedInstanceId = FALSE; LPCWSTR instanceId = NULL;
- TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName), - debugstr_guid(ClassGuid), debugstr_w(DeviceDescription), - hwndParent, CreationFlags, device_data); + TRACE("devinfo %p, name %s, class %s, description %s, hwnd %p, flags %#x, device_data %p.\n", + devinfo, debugstr_w(DeviceName), debugstr_guid(ClassGuid), debugstr_w(DeviceDescription), + hwndParent, CreationFlags, device_data);
if (!DeviceName) { SetLastError(ERROR_INVALID_DEVINST_NAME); return FALSE; } - if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); + + if (!(set = get_device_set(devinfo))) return FALSE; - } + if (!ClassGuid) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } + if (!IsEqualGUID(&set->ClassGuid, &GUID_NULL) && !IsEqualGUID(ClassGuid, &set->ClassGuid)) { @@ -1561,54 +1561,45 @@ BOOL WINAPI SetupDiRemoveDeviceInterface(HDEVINFO info, PSP_DEVICE_INTERFACE_DAT /*********************************************************************** * SetupDiEnumDeviceInfo (SETUPAPI.@) */ -BOOL WINAPI SetupDiEnumDeviceInfo( - HDEVINFO devinfo, - DWORD index, - PSP_DEVINFO_DATA info) +BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, SP_DEVINFO_DATA *device_data) { - BOOL ret = FALSE; + struct DeviceInfoSet *set; + struct device *device; + DWORD i = 0;
- TRACE("%p %d %p\n", devinfo, index, info); + TRACE("devinfo %p, index %d, device_data %p\n", devinfo, index, device_data);
- if(info==NULL) + if (!(set = get_device_set(devinfo))) + return FALSE; + + if (!device_data) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - if (devinfo && devinfo != INVALID_HANDLE_VALUE) + + if (device_data->cbSize != sizeof(SP_DEVINFO_DATA)) { - struct DeviceInfoSet *list = devinfo; - if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC) - { - if (index < list->cDevices) - { - if (info->cbSize == sizeof(SP_DEVINFO_DATA)) - { - struct device *device; - DWORD i = 0; + SetLastError(ERROR_INVALID_USER_BUFFER); + return FALSE; + }
- LIST_FOR_EACH_ENTRY(device, &list->devices, struct device, entry) - { - if (i++ == index) - { - copy_device_data(info, device); - break; - } - } - ret = TRUE; - } - else - SetLastError(ERROR_INVALID_USER_BUFFER); - } - else - SetLastError(ERROR_NO_MORE_ITEMS); + if (index >= set->cDevices) + { + SetLastError(ERROR_NO_MORE_ITEMS); + return FALSE; + } + + LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry) + { + if (i++ == index) + { + copy_device_data(device_data, device); + break; } - else - SetLastError(ERROR_INVALID_HANDLE); } - else - SetLastError(ERROR_INVALID_HANDLE); - return ret; + + return TRUE; }
/*********************************************************************** @@ -2338,24 +2329,15 @@ HDEVINFO WINAPI SetupDiGetClassDevsExW(const GUID *class, PCWSTR enumstr, HWND p /*********************************************************************** * SetupDiGetDeviceInfoListDetailA (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceInfoListDetailA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_LIST_DETAIL_DATA_A DevInfoData ) +BOOL WINAPI SetupDiGetDeviceInfoListDetailA(HDEVINFO devinfo, SP_DEVINFO_LIST_DETAIL_DATA_A *DevInfoData) { - struct DeviceInfoSet *set = DeviceInfoSet; + struct DeviceInfoSet *set;
- TRACE("%p %p\n", DeviceInfoSet, DevInfoData); + TRACE("devinfo %p, detail_data %p.\n", devinfo, DevInfoData);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(set = get_device_set(devinfo))) return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } + if (!DevInfoData || DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_A)) { @@ -2371,24 +2353,15 @@ BOOL WINAPI SetupDiGetDeviceInfoListDetailA( /*********************************************************************** * SetupDiGetDeviceInfoListDetailW (SETUPAPI.@) */ -BOOL WINAPI SetupDiGetDeviceInfoListDetailW( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_LIST_DETAIL_DATA_W DevInfoData ) +BOOL WINAPI SetupDiGetDeviceInfoListDetailW(HDEVINFO devinfo, SP_DEVINFO_LIST_DETAIL_DATA_W *DevInfoData) { - struct DeviceInfoSet *set = DeviceInfoSet; + struct DeviceInfoSet *set;
- TRACE("%p %p\n", DeviceInfoSet, DevInfoData); + TRACE("devinfo %p, detail_data %p.\n", devinfo, DevInfoData);
- if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); + if (!(set = get_device_set(devinfo))) return FALSE; - } + if (!DevInfoData || DevInfoData->cbSize != sizeof(SP_DEVINFO_LIST_DETAIL_DATA_W)) { @@ -2624,26 +2597,14 @@ BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, const GUID *class, DWORD index, SP_DEVICE_INTERFACE_DATA *iface_data) { - struct DeviceInfoSet *set = devinfo; + struct DeviceInfoSet *set; struct device *device; struct device_iface *iface; DWORD i = 0;
- TRACE("%p, %p, %s, %u, %p\n", devinfo, device_data, debugstr_guid(class), - index, iface_data); + TRACE("devinfo %p, device_data %p, class %s, index %u, iface_data %p.\n", + devinfo, device_data, debugstr_guid(class), index, iface_data);
- if (!devinfo || devinfo == INVALID_HANDLE_VALUE || - set->magic != SETUP_DEVICE_INFO_SET_MAGIC) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (device_data && (device_data->cbSize != sizeof(SP_DEVINFO_DATA) || - !device_data->Reserved)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } if (!iface_data || iface_data->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA)) { SetLastError(ERROR_INVALID_PARAMETER); @@ -2656,7 +2617,8 @@ BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO devinfo,
if (device_data) { - device = (struct device *)device_data->Reserved; + if (!(device = get_device(devinfo, device_data))) + return FALSE;
LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry) { @@ -2673,6 +2635,9 @@ BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO devinfo, } else { + if (!(set = get_device_set(devinfo))) + return FALSE; + LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry) { LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry) @@ -2708,31 +2673,21 @@ BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO devinfo, */ BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo) { - BOOL ret = FALSE; + struct DeviceInfoSet *set; + struct device *device, *device2;
- TRACE("%p\n", devinfo); - if (devinfo && devinfo != INVALID_HANDLE_VALUE) - { - struct DeviceInfoSet *list = devinfo; + TRACE("devinfo %p.\n", devinfo);
- if (list->magic == SETUP_DEVICE_INFO_SET_MAGIC) - { - struct device *device, *device2; + if (!(set = get_device_set(devinfo))) + return FALSE;
- LIST_FOR_EACH_ENTRY_SAFE(device, device2, &list->devices, - struct device, entry) - { - SETUPDI_RemoveDevice(device); - } - HeapFree(GetProcessHeap(), 0, list); - ret = TRUE; - } + LIST_FOR_EACH_ENTRY_SAFE(device, device2, &set->devices, struct device, entry) + { + SETUPDI_RemoveDevice(device); } + heap_free(set);
- if (!ret) - SetLastError(ERROR_INVALID_HANDLE); - - return ret; + return TRUE; }
/***********************************************************************