Skip to content

Add Y bounds check to InvokePrompt (Fixes #4790) #4791

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,16 +1035,24 @@ public static void DigitArgument(ConsoleKeyInfo? key = null, object arg = null)
public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null)
{
var console = _singleton._console;
console.CursorVisible = false;

if (arg is int newY)
{
if (newY < 0 || newY >= console.BufferHeight)
throw new ArgumentOutOfRangeException(nameof(arg));

console.CursorVisible = false;
console.SetCursorPosition(0, newY);
}
else
{
newY = _singleton._initialY - _singleton._options.ExtraPromptLineCount;

// Silently return if user has implicitly requested an impossible prompt invocation.
if (newY < 0)
return;

console.CursorVisible = false;
console.SetCursorPosition(0, newY);

// We need to rewrite the prompt, so blank out everything from a previous prompt invocation
Expand Down