From 0eebb64c1d651a536e2488b5e7be9b8511e6e43c Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Wed, 13 Oct 2021 10:43:49 -0400 Subject: [PATCH] sshd/terminal/terminal.go: Clamp pos to protect from some fuzzing failures --- sshd/terminal/terminal.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sshd/terminal/terminal.go b/sshd/terminal/terminal.go index ec04e8f..998c79d 100644 --- a/sshd/terminal/terminal.go +++ b/sshd/terminal/terminal.go @@ -264,6 +264,10 @@ func (t *Terminal) moveCursorToPos(pos int) { return } + if pos > len(t.line) { + pos = len(t.line) + } + x := visualLength(t.prompt) + visualLength(t.line[:pos]) y := x / t.termWidth x = x % t.termWidth