From 5b92c7b1674347f3d213434b63a6f944380af92f Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sun, 20 Dec 2009 11:17:02 +0000 Subject: [PATCH] [KS] - Return correct error code in KsPinPropertyHandler, when buffer is too small - Refactor KsTopologyPropertyHandler to make use of KsHandleSizedListQuery function which makes the function a lot smaller - Fix totally broken KsHandleSizedListQuery svn path=/trunk/; revision=44665 --- reactos/drivers/ksfilter/ks/connectivity.c | 110 ++++++++++++++------- reactos/drivers/ksfilter/ks/topology.c | 63 +----------- 2 files changed, 78 insertions(+), 95 deletions(-) diff --git a/reactos/drivers/ksfilter/ks/connectivity.c b/reactos/drivers/ksfilter/ks/connectivity.c index 5395ff2c822..3d5b9da2867 100644 --- a/reactos/drivers/ksfilter/ks/connectivity.c +++ b/reactos/drivers/ksfilter/ks/connectivity.c @@ -335,17 +335,44 @@ KsPinPropertyHandler( Size += Descriptor[Pin->PinId].DataRanges[Index]->FormatSize; } - if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size) + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == 0) { + /* buffer too small */ Irp->IoStatus.Information = Size; - Status = STATUS_MORE_ENTRIES; + Status = STATUS_BUFFER_OVERFLOW; break; } Item = (KSMULTIPLE_ITEM*)Buffer; + + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(ULONG)) + { + /* store the result size */ + Item->Size = Size; + Irp->IoStatus.Information = sizeof(ULONG); + Status = STATUS_SUCCESS; + break; + } + + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KSMULTIPLE_ITEM)) + { + /* buffer too small */ + Status = STATUS_BUFFER_TOO_SMALL; + break; + } + + /* store descriptor size */ Item->Size = Size; Item->Count = Descriptor[Pin->PinId].DataRangesCount; + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(KSMULTIPLE_ITEM)) + { + Irp->IoStatus.Information = sizeof(KSMULTIPLE_ITEM); + Status = STATUS_SUCCESS; + break; + } + + /* now copy all dataranges */ Data = (PUCHAR)(Item +1); for (Index = 0; Index < Descriptor[Pin->PinId].DataRangesCount; Index++) { @@ -402,33 +429,16 @@ KsPinPropertyHandler( break; } - /* calculate size */ - Size = sizeof(KSMULTIPLE_ITEM); - Size += max(1, Descriptor[Pin->PinId].MediumsCount) * sizeof(KSPIN_MEDIUM); - - if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size) - { - Irp->IoStatus.Information = Size; - Status = STATUS_MORE_ENTRIES; - break; - } - - Item = (KSMULTIPLE_ITEM*)Buffer; - Item->Size = Size; - if (Descriptor[Pin->PinId].MediumsCount) { - Item->Count = Descriptor[Pin->PinId].MediumsCount; - RtlMoveMemory((PVOID)(Item + 1), Descriptor[Pin->PinId].Mediums, Descriptor[Pin->PinId].MediumsCount * sizeof(KSPIN_MEDIUM)); + /* use mediums provided by driver */ + return KsHandleSizedListQuery(Irp, Descriptor[Pin->PinId].MediumsCount, sizeof(KSPIN_MEDIUM), Descriptor[Pin->PinId].Mediums); } else { - Item->Count = 1; - RtlMoveMemory((PVOID)(Item + 1), &StandardPinMedium, sizeof(KSPIN_MEDIUM)); + /* use standard medium */ + return KsHandleSizedListQuery(Irp, 1, sizeof(KSPIN_MEDIUM), &StandardPinMedium); } - - Status = STATUS_SUCCESS; - Irp->IoStatus.Information = Size; break; case KSPROPERTY_PIN_COMMUNICATION: @@ -695,28 +705,58 @@ KsHandleSizedListQuery( /* get current irp stack location */ IoStack = IoGetCurrentIrpStackLocation(Irp); + /* calculate size */ Size = DataItemSize * DataItemsCount + sizeof(KSMULTIPLE_ITEM); + /* get multiple item */ + Item = (PKSMULTIPLE_ITEM)Irp->UserBuffer; - if (IoStack->Parameters.DeviceIoControl.InputBufferLength < Size) + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == 0) { /* buffer too small */ - Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL; Irp->IoStatus.Information = Size; - return STATUS_BUFFER_TOO_SMALL; + + return STATUS_BUFFER_OVERFLOW; } - /* get multiple item */ - Item = (PKSMULTIPLE_ITEM)IoStack->Parameters.DeviceIoControl.Type3InputBuffer; + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(ULONG)) + { + /* store just the size */ + Item->Size = Size; + Irp->IoStatus.Information = sizeof(ULONG); + + return STATUS_SUCCESS; + } + + + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KSMULTIPLE_ITEM)) + { + /* buffer too small */ + return STATUS_BUFFER_TOO_SMALL; + } Item->Count = DataItemsCount; Item->Size = DataItemSize; - /* copy items */ - RtlMoveMemory((PVOID)(Item + 1), DataItems, DataItemSize * DataItemsCount); - /* store result */ - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = Size; - /* done */ - return STATUS_SUCCESS; + + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(KSMULTIPLE_ITEM)) + { + /* buffer can only hold the length descriptor */ + return STATUS_SUCCESS; + } + + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength >= Size) + { + /* copy items */ + RtlMoveMemory((PVOID)(Item + 1), DataItems, DataItemSize * DataItemsCount); + /* store result */ + Irp->IoStatus.Information = Size; + /* done */ + return STATUS_SUCCESS; + } + else + { + /* buffer too small */ + return STATUS_BUFFER_TOO_SMALL; + } } diff --git a/reactos/drivers/ksfilter/ks/topology.c b/reactos/drivers/ksfilter/ks/topology.c index 8d2288513b0..3c3ee31d103 100644 --- a/reactos/drivers/ksfilter/ks/topology.c +++ b/reactos/drivers/ksfilter/ks/topology.c @@ -152,7 +152,6 @@ KsTopologyPropertyHandler( UNICODE_STRING GuidString; UNICODE_STRING KeyName; OBJECT_ATTRIBUTES ObjectAttributes; - KSMULTIPLE_ITEM * Item; KSP_NODE * Node; PIO_STACK_LOCATION IoStack; ULONG Size; @@ -174,69 +173,13 @@ KsTopologyPropertyHandler( switch(Property->Id) { case KSPROPERTY_TOPOLOGY_CATEGORIES: - Size = sizeof(KSMULTIPLE_ITEM) + Topology->CategoriesCount * sizeof(GUID); - if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size) - { - Irp->IoStatus.Information = Size; - Status = STATUS_MORE_ENTRIES; - break; - } - - Item = (KSMULTIPLE_ITEM*)Irp->UserBuffer; - Item->Size = Size; - Item->Count = Topology->CategoriesCount; - - if (Topology->CategoriesCount) - { - RtlMoveMemory((PVOID)(Item + 1), (PVOID)Topology->Categories, Topology->CategoriesCount * sizeof(GUID)); - } - Irp->IoStatus.Information = Size; - Status = STATUS_SUCCESS; - break; + return KsHandleSizedListQuery(Irp, Topology->CategoriesCount, sizeof(GUID), Topology->Categories); case KSPROPERTY_TOPOLOGY_NODES: - Size = sizeof(KSMULTIPLE_ITEM) + Topology->TopologyNodesCount * sizeof(GUID); - if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size) - { - Irp->IoStatus.Information = Size; - Status = STATUS_MORE_ENTRIES; - break; - } - - Item = (KSMULTIPLE_ITEM*)Irp->UserBuffer; - Item->Size = Size; - Item->Count = Topology->TopologyNodesCount; - - RtlMoveMemory((PVOID)(Item + 1), (PVOID)Topology->TopologyNodes, Topology->TopologyNodesCount * sizeof(GUID)); - if (Topology->TopologyNodesCount) - { - RtlMoveMemory((PVOID)(Item + 1), (PVOID)Topology->TopologyNodes, Topology->TopologyNodesCount * sizeof(GUID)); - } - Irp->IoStatus.Information = Size; - Status = STATUS_SUCCESS; - break; + return KsHandleSizedListQuery(Irp, Topology->TopologyNodesCount, sizeof(GUID), Topology->TopologyNodes); case KSPROPERTY_TOPOLOGY_CONNECTIONS: - Size = sizeof(KSMULTIPLE_ITEM) + Topology->TopologyConnectionsCount * sizeof(KSTOPOLOGY_CONNECTION); - if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size) - { - Irp->IoStatus.Information = Size; - Status = STATUS_MORE_ENTRIES; - break; - } - - Item = (KSMULTIPLE_ITEM*)Irp->UserBuffer; - Item->Size = Size; - Item->Count = Topology->TopologyConnectionsCount; - - if (Topology->TopologyConnections) - { - RtlMoveMemory((PVOID)(Item + 1), (PVOID)Topology->TopologyConnections, Topology->TopologyConnectionsCount * sizeof(KSTOPOLOGY_CONNECTION)); - } - - Irp->IoStatus.Information = Size; - Status = STATUS_SUCCESS; - break; + return KsHandleSizedListQuery(Irp, Topology->TopologyConnectionsCount, sizeof(KSTOPOLOGY_CONNECTION), Topology->TopologyConnections); case KSPROPERTY_TOPOLOGY_NAME: Node = (KSP_NODE*)Property; -- 2.17.1