[MOUNTMGR] Simplify MountMgrQueryDosVolumePath() code (#6990)

- Use a variable of correct type instead of casting every time.
- Remove one level of indentation by returning early.
This commit is contained in:
Hermès Bélusca-Maïto 2025-01-19 22:23:56 +01:00
parent bae799382a
commit be97a36f25
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -819,6 +819,7 @@ MountMgrQueryDosVolumePath(IN PDEVICE_EXTENSION DeviceExtension,
PLIST_ENTRY SymlinksEntry; PLIST_ENTRY SymlinksEntry;
UNICODE_STRING SymbolicName; UNICODE_STRING SymbolicName;
PMOUNTMGR_TARGET_NAME Target; PMOUNTMGR_TARGET_NAME Target;
PMOUNTMGR_VOLUME_PATHS Output;
PWSTR DeviceString, OldBuffer; PWSTR DeviceString, OldBuffer;
USHORT DeviceLength, OldLength; USHORT DeviceLength, OldLength;
PDEVICE_INFORMATION DeviceInformation; PDEVICE_INFORMATION DeviceInformation;
@ -992,16 +993,20 @@ TryWithVolumeName:
} }
RtlCopyMemory(DeviceString, SymlinkInformation->Name.Buffer, DeviceLength); RtlCopyMemory(DeviceString, SymlinkInformation->Name.Buffer, DeviceLength);
/* Ensure we are in the right namespace; [1] can be ? */ /* Ensure we are in the Win32 namespace; [1] can be '?' */
DeviceString[1] = L'\\'; DeviceString[1] = L'\\';
} }
} }
/* If we found something */ /* If we didn't find something, fail */
if (DeviceString) if (!DeviceString)
{ return STATUS_NOT_FOUND;
/* Get the output buffer */
Output = (PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer;
/* At least, we will return our length */ /* At least, we will return our length */
((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSzLength = DeviceLength; Output->MultiSzLength = DeviceLength;
/* MOUNTMGR_VOLUME_PATHS is a string + a ULONG */ /* MOUNTMGR_VOLUME_PATHS is a string + a ULONG */
Irp->IoStatus.Information = DeviceLength + sizeof(ULONG); Irp->IoStatus.Information = DeviceLength + sizeof(ULONG);
@ -1011,27 +1016,24 @@ TryWithVolumeName:
/* Copy it */ /* Copy it */
if (DeviceLength) if (DeviceLength)
{ {
RtlCopyMemory(((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSz, DeviceString, DeviceLength); RtlCopyMemory(Output->MultiSz, DeviceString, DeviceLength);
} }
/* And double zero at its end - this is needed in case of multiple paths which are separated by a single 0 */ /* And double-NUL at its end - this is needed in case of
* multiple paths which are separated by a single NUL */
FreePool(DeviceString); FreePool(DeviceString);
((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSz[DeviceLength / sizeof(WCHAR)] = 0; Output->MultiSz[DeviceLength / sizeof(WCHAR)] = UNICODE_NULL;
((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSz[DeviceLength / sizeof(WCHAR) + 1] = 0; Output->MultiSz[DeviceLength / sizeof(WCHAR) + 1] = UNICODE_NULL;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
else else
{ {
/* Just return appropriate size and leave */ /* Just return the size needed and leave */
FreePool(DeviceString); FreePool(DeviceString);
Irp->IoStatus.Information = sizeof(ULONG); Irp->IoStatus.Information = sizeof(ULONG);
return STATUS_BUFFER_OVERFLOW; return STATUS_BUFFER_OVERFLOW;
} }
}
/* Fail */
return STATUS_NOT_FOUND;
} }
/* /*
@ -1557,7 +1559,7 @@ MountMgrQueryDosVolumePaths(IN PDEVICE_EXTENSION DeviceExtension,
MountMgrNotifyNameChange(DeviceExtension, &SymbolicName, FALSE); MountMgrNotifyNameChange(DeviceExtension, &SymbolicName, FALSE);
} }
/* Get output buffer */ /* Get the output buffer */
Output = (PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer; Output = (PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer;
/* Set required size */ /* Set required size */
@ -1566,7 +1568,7 @@ MountMgrQueryDosVolumePaths(IN PDEVICE_EXTENSION DeviceExtension,
/* Compute total length */ /* Compute total length */
OutputLength = Output->MultiSzLength + sizeof(ULONG); OutputLength = Output->MultiSzLength + sizeof(ULONG);
/* If it cannot fit, just return need size and quit */ /* If it cannot fit, just return the size needed and leave */
if (OutputLength > Stack->Parameters.DeviceIoControl.OutputBufferLength) if (OutputLength > Stack->Parameters.DeviceIoControl.OutputBufferLength)
{ {
Irp->IoStatus.Information = sizeof(ULONG); Irp->IoStatus.Information = sizeof(ULONG);