- 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:
Johannes Anderwald 2010-09-23 11:36:00 +00:00
parent cf358ed153
commit 10eb63f2df
2 changed files with 10 additions and 64 deletions

View file

@ -186,3 +186,9 @@ KspValidateConnectRequest(
IN PVOID Descriptors, IN PVOID Descriptors,
IN ULONG DescriptorSize, IN ULONG DescriptorSize,
OUT PKSPIN_CONNECT* Connect); OUT PKSPIN_CONNECT* Connect);
NTSTATUS
KspReadMediaCategory(
IN LPGUID Category,
PKEY_VALUE_PARTIAL_INFORMATION *OutInformation);

View file

@ -147,16 +147,9 @@ KsTopologyPropertyHandler(
IN OUT PVOID Data, IN OUT PVOID Data,
IN const KSTOPOLOGY* Topology) 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; KSP_NODE * Node;
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
ULONG Size;
NTSTATUS Status; NTSTATUS Status;
HANDLE hKey;
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo; PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
@ -191,79 +184,26 @@ KsTopologyPropertyHandler(
break; break;
} }
Status = RtlStringFromGUID(&Topology->TopologyNodesNames[Node->NodeId], &GuidString); Status = KspReadMediaCategory((LPGUID)&Topology->TopologyNodesNames[Node->NodeId], &KeyInfo);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
break; break;
} }
KeyName.Length = 0; Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
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;
}
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) if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
{ {
Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR); Status = STATUS_BUFFER_OVERFLOW;
Status = STATUS_MORE_ENTRIES;
FreeItem(KeyInfo); FreeItem(KeyInfo);
break; break;
} }
RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength); RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength);
((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0'; ((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
FreeItem(KeyInfo); FreeItem(KeyInfo);
break; break;
default: default:
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;