Author: janderwald
Date: Sun Dec 20 12:17:02 2009
New Revision: 44665
URL:
http://svn.reactos.org/svn/reactos?rev=44665&view=rev
Log:
[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
Modified:
trunk/reactos/drivers/ksfilter/ks/connectivity.c
trunk/reactos/drivers/ksfilter/ks/topology.c
Modified: trunk/reactos/drivers/ksfilter/ks/connectivity.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/connec…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/connectivity.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/connectivity.c [iso-8859-1] Sun Dec 20 12:17:02
2009
@@ -335,17 +335,44 @@
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 @@
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));
- }
-
- Status = STATUS_SUCCESS;
- Irp->IoStatus.Information = Size;
+ /* use standard medium */
+ return KsHandleSizedListQuery(Irp, 1, sizeof(KSPIN_MEDIUM),
&StandardPinMedium);
+ }
break;
case KSPROPERTY_PIN_COMMUNICATION:
@@ -695,28 +705,58 @@
/* get current irp stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp);
+ /* calculate size */
Size = DataItemSize * DataItemsCount + sizeof(KSMULTIPLE_ITEM);
-
- if (IoStack->Parameters.DeviceIoControl.InputBufferLength < Size)
+ /* get multiple item */
+ Item = (PKSMULTIPLE_ITEM)Irp->UserBuffer;
+
+ if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == 0)
{
/* buffer too small */
- Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
Irp->IoStatus.Information = Size;
+
+ return STATUS_BUFFER_OVERFLOW;
+ }
+
+ 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;
}
-
- /* get multiple item */
- Item = (PKSMULTIPLE_ITEM)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
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;
+ }
}
Modified: trunk/reactos/drivers/ksfilter/ks/topology.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/topolo…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/topology.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/topology.c [iso-8859-1] Sun Dec 20 12:17:02 2009
@@ -152,7 +152,6 @@
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 @@
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;