Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

Invalid MaxPhysicalWindowSize set by sshd

Open creack opened this issue 1 year ago • 4 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest version
  • [X] Search the existing issues.

Steps to reproduce

  • Install a brand new vanilla windows 2022 server without desktop (in my case in a proxmox VM with default settings, win2022 ISO downloaded from MS website as an evaluation copy).
  • Install OpenSSH with sshd
  • Connect to it from a remote client
  • Check $Host.UI.RawUI.MaxPhysicalWindowSize

Expected behavior

$Host.UI.RawUI.MaxPhysicalWindowSize should be at least as big as the client's size.

Actual behavior

$Host.UI.RawUI.MaxPhysicalWindowSize is smaller than $Host.UI.RawUI.WindowSize, resulting in tools trying to restore termcaps to use the wrong values.

Example: open/close vim.

Error details

Initially posted on the docs repo MicrosoftDocs/Console-Docs#302, but as the bug impacts openssh, reposting it here as well.

Environment data

PS C:\Users\Administrator> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.9
PSEdition                      Core
GitCommitId                    7.3.9
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

v9.4.0.0p1-Beta (OpenSSH_for_Windows_9.4, LibreSSL 3.7.3)

Visuals

Example:

  • Check client terminal size
  • Connect to the windows 2022 (no desktop) host
  • Check $Host.UI.RawUI values - Notice MaxPhysicalWindowSize is lower than WindowSize
  • Open/Close vim
  • Check $Host.UI.RawUI again - Notice that vim restored the wrong value, resulting in a broken terminal.
$> stty size
50 145
$> ssh wintest1
PowerShell 7.3.9
PS C:\Users\Administrator> $Host.UI.RawUI

ForegroundColor       : Gray
BackgroundColor       : Black
CursorPosition        : 0,2
WindowPosition        : 0,0
CursorSize            : 25
BufferSize            : 145,50
WindowSize            : 145,50
MaxWindowSize         : 145,50
MaxPhysicalWindowSize : 1008,45
KeyAvailable          : True
WindowTitle           : Administrator: C:\Windows\system32\conhost.exe


PS C:\Users\Administrator> vim
PS C:\Users\Administrator> $Host.UI.RawUI

ForegroundColor       : Gray
BackgroundColor       : Black
CursorPosition        : 0,18
WindowPosition        : 0,0
CursorSize            : 25
BufferSize            : 145,45
WindowSize            : 145,45
MaxWindowSize         : 145,45
MaxPhysicalWindowSize : 1008,45
KeyAvailable          : True
WindowTitle           : Administrator: C:\Windows\system32\conhost.exe


PS C:\Users\Administrator>

creack avatar Nov 09 '23 14:11 creack

Can you please test with 9.4 (https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v9.4.0.0p1-Beta)?

8.0 is about 4 years old so I hope that it might have been fixed

matso42 avatar Nov 10 '23 17:11 matso42

@matso42 confirmed, the bug is still there with 9.4

PS C:\Users\Administrator> $Host.UI.RawUI

ForegroundColor       : Gray
BackgroundColor       : Black
CursorPosition        : 0,2
WindowPosition        : 0,0
CursorSize            : 25
BufferSize            : 292,69
WindowSize            : 292,69
MaxWindowSize         : 292,69
MaxPhysicalWindowSize : 1008,45
KeyAvailable          : True
WindowTitle           : Administrator: C:\Windows\system32\conhost.exe

PS C:\Program Files\OpenSSH> .\sshd.exe -V
OpenSSH_for_Windows_9.4, LibreSSL 3.7.3

creack avatar Nov 10 '23 20:11 creack

Hmm, I may need additional details to setup a repro. I tried to ssh from an Ubuntu-20 machine to a ssh server on a Windows 11 machine, and it seems like $Host.UI.RawUI.MaxPhysicalWindowSize gets set to a value larger than $Host.UI.RawUI.WindowSize, as expected.

What type of machine is the ssh client connecting from?

Any chance the machine with the ssh server is accessible without ssh? I'm curious what the value of $Host.UI.RawUI.MaxPhysicalWindowSize is outside of an ssh session.

tgauth avatar Nov 13 '23 21:11 tgauth

I suspect the issue would be seen only if the target server doesn't have a desktop nor a physical display. Connecting to a Windows 11 desktop will likely not show the issue.

I am trying from OSX, getting the same behavior under iTerm2 and Terminal. I also tried from a desktop windows 10 using windows terminal and got the same behavior.

I am getting the same results while working on a Go port for a pty library, I can't find a way to set the value, and I suspect OpenSSH doesn't set it either.

Here are the results from within the server UI:

Initial boot:

Screenshot 2023-11-14 at 7 28 43 AM

Values from there directly look correct:

Screenshot 2023-11-14 at 7 30 26 AM

Using ssh client to localhost, looks wrong (smaller size than local and exact same value as when connected from somewhere else):

Screenshot 2023-11-14 at 7 30 53 AM

creack avatar Nov 14 '23 12:11 creack