[KS]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Mon, 18 Oct 2010 22:21:00 +0000 (22:21 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Mon, 18 Oct 2010 22:21:00 +0000 (22:21 +0000)
- Fix KSPROPERTY_PIN_CATEGORY handler when no category is provided
- Fix KSPROPERTY_PIN_NAME handler when there is no name provided. Use fallback pin category. If there is no category provided, fail with correct error code
- Fix KSPROPERTY_TOPOLOGY_NAME handler by checking if there is a node name provided. If not use node type as fallback.
- Return correct error code when property request id is out of bounds

svn path=/trunk/; revision=49199

reactos/drivers/ksfilter/ks/connectivity.c
reactos/drivers/ksfilter/ks/topology.c

index b20263a..2825221 100644 (file)
@@ -330,6 +330,7 @@ KspPinPropertyHandler(
     NTSTATUS Status = STATUS_NOT_SUPPORTED;
     ULONG Count;
     const PKSDATARANGE* DataRanges;
+    LPGUID Guid;
 
     IoStack = IoGetCurrentIrpStackLocation(Irp);
     Buffer = Irp->UserBuffer;
@@ -509,48 +510,77 @@ KspPinPropertyHandler(
 
         case KSPROPERTY_PIN_CATEGORY:
 
+            if (!Descriptor->Category)
+            {
+                /* no pin category */
+                return STATUS_NOT_FOUND;
+            }
+
+            /* check size */
             Size = sizeof(GUID);
             if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size)
             {
+                /* buffer too small */
                 Irp->IoStatus.Information = Size;
                 Status = STATUS_BUFFER_TOO_SMALL;
                 break;
             }
-            if (Descriptor->Category)
-            {
-                RtlMoveMemory(Buffer, Descriptor->Category, sizeof(GUID));
-            }
 
+            /* copy category guid */
+            RtlMoveMemory(Buffer, Descriptor->Category, sizeof(GUID));
+
+            /* save result */
             Status = STATUS_SUCCESS;
             Irp->IoStatus.Information = Size;
             break;
 
         case KSPROPERTY_PIN_NAME:
-            if (!Descriptor->Name)
+
+            if (Descriptor->Name)
             {
-                Irp->IoStatus.Information = 0;
-                Status = STATUS_SUCCESS;
-                break;
+                /* use pin name */
+                Guid = (LPGUID)Descriptor->Name;
+            }
+            else
+            {
+                /* use pin category as fallback */
+                Guid = (LPGUID)Descriptor->Category;
+            }
+
+            if (!Guid)
+            {
+                /* no friendly name available */
+                return STATUS_NOT_FOUND;
             }
 
-            Status = KspReadMediaCategory((LPGUID)Descriptor->Name, &KeyInfo);
+            /* read friendly name category name */
+            Status = KspReadMediaCategory(Guid, &KeyInfo);
             if (!NT_SUCCESS(Status))
             {
+                /* failed to read category */
                 Irp->IoStatus.Information = 0;
                 break;
             }
 
+            /* store required length */
             Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
 
+            /* check if buffer is too small */
             if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
             {
+                /* buffer too small */
                 Status = STATUS_BUFFER_OVERFLOW;
                 FreeItem(KeyInfo);
                 break;
             }
 
+            /* copy result */
             RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength);
+
+            /* null terminate name */
             ((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
+
+            /* free key info */
             FreeItem(KeyInfo);
             break;
         case KSPROPERTY_PIN_PROPOSEDATAFORMAT:
index 096d36c..321f0ba 100644 (file)
@@ -151,6 +151,7 @@ KsTopologyPropertyHandler(
     PIO_STACK_LOCATION IoStack;
     NTSTATUS Status;
     PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
+    LPGUID Guid;
 
     IoStack = IoGetCurrentIrpStackLocation(Irp);
 
@@ -177,37 +178,60 @@ KsTopologyPropertyHandler(
         case KSPROPERTY_TOPOLOGY_NAME:
             Node = (KSP_NODE*)Property;
 
+            /* check for invalid node id */
             if (Node->NodeId >= Topology->TopologyNodesCount)
             {
+                /* invalid node id */
                 Irp->IoStatus.Information = 0;
                 Status = STATUS_INVALID_PARAMETER;
                 break;
             }
 
-            Status = KspReadMediaCategory((LPGUID)&Topology->TopologyNodesNames[Node->NodeId], &KeyInfo);
+            /* check if there is a name supplied */
+            if (!IsEqualGUIDAligned(&Topology->TopologyNodesNames[Node->NodeId], &GUID_NULL))
+            {
+                /* node name has been supplied */
+                Guid = (LPGUID)&Topology->TopologyNodesNames[Node->NodeId];
+            }
+            else
+            {
+                /* fallback to topology node type */
+                Guid = (LPGUID)&Topology->TopologyNodes[Node->NodeId];
+            }
+
+            /* read topology node name */
+            Status = KspReadMediaCategory(Guid, &KeyInfo);
             if (!NT_SUCCESS(Status))
             {
                 Irp->IoStatus.Information = 0;
                 break;
             }
 
+            /* store result size */
             Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
 
+            /* check for buffer overflow */
             if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
             {
+                /* buffer too small */
                 Status = STATUS_BUFFER_OVERFLOW;
                 FreeItem(KeyInfo);
                 break;
             }
 
+            /* copy result buffer */
             RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength);
+
+            /* zero terminate it */
             ((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
+
+            /* free key info */
             FreeItem(KeyInfo);
 
             break;
         default:
              Irp->IoStatus.Information = 0;
-           Status = STATUS_NOT_IMPLEMENTED;
+           Status = STATUS_NOT_FOUND;
     }