Skip to content

Commit addd1a6

Browse files
authored
Add bound check for the cursor top value to InvokePrompt (#4791)
1 parent 9b6a47d commit addd1a6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

PSReadLine/ReadLine.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,16 +1035,28 @@ public static void DigitArgument(ConsoleKeyInfo? key = null, object arg = null)
10351035
public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null)
10361036
{
10371037
var console = _singleton._console;
1038-
console.CursorVisible = false;
10391038

10401039
if (arg is int newY)
10411040
{
1041+
if (newY < 0 || newY >= console.BufferHeight)
1042+
{
1043+
throw new ArgumentOutOfRangeException(nameof(arg));
1044+
}
1045+
1046+
console.CursorVisible = false;
10421047
console.SetCursorPosition(0, newY);
10431048
}
10441049
else
10451050
{
10461051
newY = _singleton._initialY - _singleton._options.ExtraPromptLineCount;
10471052

1053+
// Silently return if user has implicitly requested an impossible prompt invocation.
1054+
if (newY < 0)
1055+
{
1056+
return;
1057+
}
1058+
1059+
console.CursorVisible = false;
10481060
console.SetCursorPosition(0, newY);
10491061

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

0 commit comments

Comments
 (0)