From 220f6814ba23b80b5f5f42f814dd173f950fbf7b Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Tue, 14 Mar 2023 23:07:06 +0300 Subject: [PATCH] fixed buffer overflooding in ShowMenu function --- src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 | 9 ++------- .../Module/Sophia.psm1 | 9 ++------- .../Module/Sophia.psm1 | 9 ++------- .../Module/Sophia.psm1 | 9 ++------- src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 | 9 ++------- .../Module/Sophia.psm1 | 9 ++------- 6 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 9d757fad..57fbd919 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -6929,18 +6929,13 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int $Default ) - # There's a bug in Windows Terminal with double text in console - # https://github.com/microsoft/terminal/issues/14992 - if ($env:WT_SESSION) - { - Clear-Host - } - Write-Information -MessageData $Title -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue # Extract the localized "Skip" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(16956) + # https://github.com/microsoft/terminal/issues/14992 + [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 12ef9b95..d747cfb2 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -5616,18 +5616,13 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int $Default ) - # There's a bug in Windows Terminal with double text in console - # https://github.com/microsoft/terminal/issues/14992 - if ($env:WT_SESSION) - { - Clear-Host - } - Write-Information -MessageData $Title -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue # Extract the localized "Skip" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(16956) + # https://github.com/microsoft/terminal/issues/14992 + [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 963a0802..b0263061 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -6003,18 +6003,13 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int $Default ) - # There's a bug in Windows Terminal with double text in console - # https://github.com/microsoft/terminal/issues/14992 - if ($env:WT_SESSION) - { - Clear-Host - } - Write-Information -MessageData $Title -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue # Extract the localized "Skip" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(16956) + # https://github.com/microsoft/terminal/issues/14992 + [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 1845b38d..c4ab691f 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -6938,18 +6938,13 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int $Default ) - # There's a bug in Windows Terminal with double text in console - # https://github.com/microsoft/terminal/issues/14992 - if ($env:WT_SESSION) - { - Clear-Host - } - Write-Information -MessageData $Title -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue # Extract the localized "Skip" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(16956) + # https://github.com/microsoft/terminal/issues/14992 + [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 93e5a0cb..b22d9e39 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -6498,18 +6498,13 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int $Default ) - # There's a bug in Windows Terminal with double text in console - # https://github.com/microsoft/terminal/issues/14992 - if ($env:WT_SESSION) - { - Clear-Host - } - Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData $Title -InformationAction Continue # Extract the localized "Skip" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(16956) + # https://github.com/microsoft/terminal/issues/14992 + [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index 8f9db609..d378489c 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -6505,18 +6505,13 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int $Default ) - # There's a bug in Windows Terminal with double text in console - # https://github.com/microsoft/terminal/issues/14992 - if ($env:WT_SESSION) - { - Clear-Host - } - Write-Information -MessageData $Title -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue # Extract the localized "Skip" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(16956) + # https://github.com/microsoft/terminal/issues/14992 + [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0)