Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid MaxPhysicalWindowSize set by sshd #2177

Open
3 tasks done
creack opened this issue Nov 9, 2023 · 4 comments
Open
3 tasks done

Invalid MaxPhysicalWindowSize set by sshd #2177

creack opened this issue Nov 9, 2023 · 4 comments
Assignees

Comments

@creack
Copy link

creack commented Nov 9, 2023

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • 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 creack changed the title Invalid MaxPhysicalWindowSize Invalid MaxPhysicalWindowSize set by sshd Nov 9, 2023
@matso42
Copy link

matso42 commented Nov 10, 2023

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

@creack
Copy link
Author

creack commented Nov 10, 2023

@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

@tgauth
Copy link
Collaborator

tgauth commented Nov 13, 2023

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.

@creack
Copy link
Author

creack commented Nov 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants