maybe fix out of bounds (#843)

This commit is contained in:
Zachary Rice authored and GitHub committed 2022-04-18 14:57:40 -05:00
1 parent 48b79facfa
commit d8cd93cabe
2 files changed
+7 -3

No files matched your search

+4 -1
View File
@@ -4,6 +4,7 @@ import (
_ "embed"
"fmt"
"regexp"
"strings"
)
//go:embed gitleaks.toml
@@ -64,7 +65,9 @@ func (vc *ViperConfig) Translate() (Config, error) {
if r.Keywords == nil {
r.Keywords = []string{}
} else {
keywords = append(keywords, r.Keywords...)
for _, k := range r.Keywords {
keywords = append(keywords, strings.ToLower(k))
}
}
if r.Tags == nil {
+3 -2
View File
@@ -393,9 +393,10 @@ func (d *Detector) Detect(fragment Fragment) []report.Finding {
fragment.newlineIndices = regexp.MustCompile("\n").FindAllStringIndex(fragment.Raw, -1)
// build keyword map for prefiltering rules
matches := d.prefilter.FindAll(strings.ToLower(fragment.Raw))
normalizedRaw := strings.ToLower(fragment.Raw)
matches := d.prefilter.FindAll(normalizedRaw)
for _, m := range matches {
fragment.keywords[strings.ToLower(fragment.Raw[m.Start():m.End()])] = true
fragment.keywords[normalizedRaw[m.Start():m.End()]] = true
}
for _, rule := range d.Config.Rules {