mirror of
https://github.com/reactos/reactos.git
synced 2024-10-05 00:43:21 +00:00
[KS]
- Simplify KsTopologyPropertyHandler by using KspReadMediaCategory helper - Return correct status code in case of an overflow svn path=/trunk/; revision=48850
This commit is contained in:
parent
cf358ed153
commit
10eb63f2df
|
@ -186,3 +186,9 @@ KspValidateConnectRequest(
|
|||
IN PVOID Descriptors,
|
||||
IN ULONG DescriptorSize,
|
||||
OUT PKSPIN_CONNECT* Connect);
|
||||
|
||||
NTSTATUS
|
||||
KspReadMediaCategory(
|
||||
IN LPGUID Category,
|
||||
PKEY_VALUE_PARTIAL_INFORMATION *OutInformation);
|
||||
|
||||
|
|
|
@ -147,16 +147,9 @@ KsTopologyPropertyHandler(
|
|||
IN OUT PVOID Data,
|
||||
IN const KSTOPOLOGY* Topology)
|
||||
{
|
||||
UNICODE_STRING LocalMachine = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\MediaCategories\\");
|
||||
UNICODE_STRING Name = RTL_CONSTANT_STRING(L"Name");
|
||||
UNICODE_STRING GuidString;
|
||||
UNICODE_STRING KeyName;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
KSP_NODE * Node;
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
ULONG Size;
|
||||
NTSTATUS Status;
|
||||
HANDLE hKey;
|
||||
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
@ -191,79 +184,26 @@ KsTopologyPropertyHandler(
|
|||
break;
|
||||
}
|
||||
|
||||
Status = RtlStringFromGUID(&Topology->TopologyNodesNames[Node->NodeId], &GuidString);
|
||||
Status = KspReadMediaCategory((LPGUID)&Topology->TopologyNodesNames[Node->NodeId], &KeyInfo);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
Irp->IoStatus.Information = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
KeyName.Length = 0;
|
||||
KeyName.MaximumLength = LocalMachine.Length + GuidString.Length + sizeof(WCHAR);
|
||||
KeyName.Buffer = AllocateItem(PagedPool, KeyName.MaximumLength);
|
||||
if (!KeyName.Buffer)
|
||||
{
|
||||
Irp->IoStatus.Information = 0;
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
RtlFreeUnicodeString(&GuidString);
|
||||
break;
|
||||
}
|
||||
Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
|
||||
|
||||
RtlAppendUnicodeStringToString(&KeyName, &LocalMachine);
|
||||
RtlAppendUnicodeStringToString(&KeyName, &GuidString);
|
||||
|
||||
RtlFreeUnicodeString(&GuidString);
|
||||
|
||||
InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
||||
Status = ZwOpenKey(&hKey, GENERIC_READ, &ObjectAttributes);
|
||||
|
||||
FreeItem(KeyName.Buffer);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status);
|
||||
Irp->IoStatus.Information = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
Status = ZwQueryValueKey(hKey, &Name, KeyValuePartialInformation, NULL, 0, &Size);
|
||||
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
ZwClose(hKey);
|
||||
Irp->IoStatus.Information = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT(Size);
|
||||
KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION) AllocateItem(NonPagedPool, Size);
|
||||
if (!KeyInfo)
|
||||
{
|
||||
Status = STATUS_NO_MEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
Status = ZwQueryValueKey(hKey, &Name, KeyValuePartialInformation, (PVOID)KeyInfo, Size, &Size);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
FreeItem(KeyInfo);
|
||||
ZwClose(hKey);
|
||||
Irp->IoStatus.Information = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ZwClose(hKey);
|
||||
if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
|
||||
{
|
||||
Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
|
||||
Status = STATUS_MORE_ENTRIES;
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
FreeItem(KeyInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength);
|
||||
((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
|
||||
Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
|
||||
FreeItem(KeyInfo);
|
||||
|
||||
break;
|
||||
default:
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
|
Loading…
Reference in a new issue