From 882463c462272b0ce7b1c3ae98233ed11ecfa381 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Mon, 1 Sep 2025 11:15:57 +0200 Subject: [PATCH] adding breakout after max iterations --- pkg/utils/telnetmini/telnet.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/utils/telnetmini/telnet.go b/pkg/utils/telnetmini/telnet.go index 2047090f4..6c65cdb61 100644 --- a/pkg/utils/telnetmini/telnet.go +++ b/pkg/utils/telnetmini/telnet.go @@ -275,7 +275,16 @@ func (c *Client) readUntil(ctx context.Context, needles ...string) (matched stri var b strings.Builder tmp := make([]byte, 1) + // Maximum iteration counter to prevent infinite loops + maxIterations := 20 + iterationCount := 0 + for { + iterationCount++ + // if we have iterated more than maxIterations, return + if iterationCount > maxIterations { + return "", b.String(), nil + } // honor context deadline on every read c.setDeadlineFromCtx(ctx, false) _, err := c.rd.Read(tmp)