[MOUNTMGR] Don't overrun output buffer in QueryPointsFromMemory
[reactos.git] / drivers / filters / mountmgr / point.c
index 3eab7c3..4c1d843 100644 (file)
@@ -23,8 +23,6 @@
  * PROGRAMMER:       Pierre Schweitzer (pierre.schweitzer@reactos.org)
  */
 
-/* INCLUDES *****************************************************************/
-
 #include "mntmgr.h"
 
 #define NDEBUG
@@ -223,7 +221,7 @@ MountMgrCreatePointWorker(IN PDEVICE_EXTENSION DeviceExtension,
     FreePool(SymLink.Buffer);
     MountMgrNotify(DeviceExtension);
 
-    if (!DeviceInformation->Volume)
+    if (!DeviceInformation->ManuallyRegistered)
     {
         MountMgrNotifyNameChange(DeviceExtension, DeviceName, FALSE);
     }
@@ -324,7 +322,7 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
     {
         if (DeviceEntry == &(DeviceExtension->DeviceListHead))
         {
-            if (DeviceName.Buffer)
+            if (SymbolicName)
             {
                 FreePool(DeviceName.Buffer);
             }
@@ -334,15 +332,18 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
     }
 
     /* Now, ensure output buffer can hold everything */
-    Stack = IoGetNextIrpStackLocation(Irp);
+    Stack = IoGetCurrentIrpStackLocation(Irp);
     MountPoints = (PMOUNTMGR_MOUNT_POINTS)Irp->AssociatedIrp.SystemBuffer;
 
     /* Ensure we set output to let user reallocate! */
     MountPoints->Size = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalSize;
     MountPoints->NumberOfMountPoints = TotalSymLinks;
+    Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalSize;
 
     if (MountPoints->Size > Stack->Parameters.DeviceIoControl.OutputBufferLength)
     {
+        Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS);
+
         return STATUS_BUFFER_OVERFLOW;
     }
 
@@ -358,7 +359,7 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
         /* Find back correct mount point */
         if (UniqueId)
         {
-            if (!UniqueId->UniqueIdLength != DeviceInformation->UniqueId->UniqueIdLength)
+            if (UniqueId->UniqueIdLength != DeviceInformation->UniqueId->UniqueIdLength)
             {
                 continue;
             }
@@ -519,7 +520,7 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
     }
 
     /* Get output buffer */
-    Stack = IoGetNextIrpStackLocation(Irp);
+    Stack = IoGetCurrentIrpStackLocation(Irp);
     MountPoints = (PMOUNTMGR_MOUNT_POINTS)Irp->AssociatedIrp.SystemBuffer;
 
     /* Compute output length */
@@ -529,9 +530,12 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
     /* Give length to allow reallocation */
     MountPoints->Size = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalLength;
     MountPoints->NumberOfMountPoints = 1;
+    Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalLength;
 
     if (MountPoints->Size > Stack->Parameters.DeviceIoControl.OutputBufferLength)
     {
+        Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS);
+
         return STATUS_BUFFER_OVERFLOW;
     }