From ff25b979421cc2bf9ac2b5b44162d24e5031b426 Mon Sep 17 00:00:00 2001 From: davidreis97 Date: Sun, 23 Aug 2020 22:57:44 +0100 Subject: [PATCH 1/3] Detect CONIN$ and CONOUT$ as reserved names in Win --- src/System.Management.Automation/engine/Utils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index bce78b3543d..4ecab9fc445 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -1258,7 +1258,7 @@ internal static bool IsAdministrator() internal static bool IsReservedDeviceName(string destinationPath) { #if !UNIX - string[] reservedDeviceNames = { "CON", "PRN", "AUX", "CLOCK$", "NUL", + string[] reservedDeviceNames = { "CON", "PRN", "AUX", "CLOCK$", "NUL", "CONIN$", "CONOUT$", "COM0", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" }; string compareName = Path.GetFileName(destinationPath); From ee101c301e36ded421e81af04ce8927e5949f718 Mon Sep 17 00:00:00 2001 From: davidreis97 Date: Sun, 23 Aug 2020 23:29:58 +0100 Subject: [PATCH 2/3] Change max length of filenames checked as reserved Max size set to 7 in order to also detect the reserved name "CONOUT$" --- src/System.Management.Automation/engine/Utils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 4ecab9fc445..89ffe95ec9a 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -1264,8 +1264,8 @@ internal static bool IsReservedDeviceName(string destinationPath) string compareName = Path.GetFileName(destinationPath); string noExtensionCompareName = Path.GetFileNameWithoutExtension(destinationPath); - if (((compareName.Length < 3) || (compareName.Length > 6)) && - ((noExtensionCompareName.Length < 3) || (noExtensionCompareName.Length > 6))) + if (((compareName.Length < 3) || (compareName.Length > 7)) && + ((noExtensionCompareName.Length < 3) || (noExtensionCompareName.Length > 7))) { return false; } From e75773f51a4f82a0aa8d98b28e7dd214e93966ad Mon Sep 17 00:00:00 2001 From: davidreis97 Date: Sun, 23 Aug 2020 23:38:46 +0100 Subject: [PATCH 3/3] Add CONIN$, CONOUT$ to reserved names Pester test --- .../Microsoft.PowerShell.Management/FileSystem.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index 015ad53ccd0..0e4adaeec70 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -28,6 +28,8 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { @{ deviceName = 'AUX' } @{ deviceName = 'CLOCK$' } @{ deviceName = 'NUL' } + @{ deviceName = 'CONIN$' } + @{ deviceName = 'CONOUT$' } @{ deviceName = 'COM0' } @{ deviceName = 'COM1' } @{ deviceName = 'COM2' }