mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
[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
This commit is contained in:
parent
f45bd7617a
commit
5b92c7b167
2 changed files with 78 additions and 95 deletions
|
@ -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_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;
|
||||
|
||||
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.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = Size;
|
||||
/* done */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* buffer too small */
|
||||
return STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue