From 56079dc9eac0a6f46f670ce35f798e9f4146332f Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Wed, 29 Mar 2023 07:37:46 -0600 Subject: [PATCH] safer out of bounds (#1135) --- detect/utils.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/detect/utils.go b/detect/utils.go index 4886dcd2..1a499513 100644 --- a/detect/utils.go +++ b/detect/utils.go @@ -122,7 +122,14 @@ func printFinding(f report.Finding) { Italic(true). Foreground(lipgloss.Color("#f05c07")) matchEnd := lipgloss.NewStyle().SetString(f.Match[secretInMatchIdx+len(f.Secret):]).Foreground(lipgloss.Color("#f5d445")) + + lineEndIdx := matchInLineIDX + len(f.Match) + if len(f.Line)-1 <= lineEndIdx { + lineEndIdx = len(f.Line) - 1 + } + lineEnd := f.Line[matchInLineIDX+len(f.Match):] + if len(f.Secret) > 100 { secret = lipgloss.NewStyle().SetString(f.Secret[0:100] + "..."). Bold(true).