From 8bb7cd286bc106dd67a869e045d589960873bd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 19 Jan 2025 23:00:04 +0100 Subject: [PATCH] [MOUNTMGR] Fix three more bugs in MountMgrQueryDosVolumePath() (#6990) - When trying to find a device, don't fail with STATUS_NOT_FOUND if no associated symbolic links are present. Instead, that test was wrong, and should go out of the search loop to do the drive-letter processing. Addendum to commit f9f5a78715. - In addition, when using the associated-device method, fix the list used to retrieve the corresponding device. - In the TryWithVolumeName: block, reset DeviceString to NULL after freeing, so that we can correctly fail with STATUS_NOT_FOUND if no suitable device was found, before initializing the output data. --- drivers/storage/mountmgr/device.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/storage/mountmgr/device.c b/drivers/storage/mountmgr/device.c index fdf6af9435b..22710b7b4d7 100644 --- a/drivers/storage/mountmgr/device.c +++ b/drivers/storage/mountmgr/device.c @@ -887,20 +887,16 @@ MountMgrQueryDosVolumePath(IN PDEVICE_EXTENSION DeviceExtension, } } - /* We didn't find, break */ - if (SymlinksEntry == &(DeviceInformation->SymbolicLinksListHead)) - { - return STATUS_NOT_FOUND; - } + /* If we've found a device via drive letter, do default processing */ + if (SymlinksEntry != &(DeviceInformation->SymbolicLinksListHead)) + break; - /* It doesn't have associated device, go to fallback method */ + /* If it doesn't have an associated device, go to fallback method */ if (IsListEmpty(&DeviceInformation->AssociatedDevicesHead)) - { goto TryWithVolumeName; - } /* Create a string with the information about the device */ - AssociatedDevice = CONTAINING_RECORD(&(DeviceInformation->SymbolicLinksListHead), ASSOCIATED_DEVICE_ENTRY, AssociatedDevicesEntry); + AssociatedDevice = CONTAINING_RECORD(&(DeviceInformation->AssociatedDevicesHead), ASSOCIATED_DEVICE_ENTRY, AssociatedDevicesEntry); OldLength = DeviceLength; OldBuffer = DeviceString; DeviceLength += AssociatedDevice->String.Length; @@ -967,6 +963,7 @@ TryWithVolumeName: if (DeviceString) { FreePool(DeviceString); + DeviceString = NULL; DeviceLength = 0; }