This commit is contained in:
Zachary Rice authored and GitHub committed 2024-12-20 05:46:25 -06:00
1 parent a9e6d8c9a7
commit 8a8306288e
3 files changed
+52 -2

No files matched your search

+10
View File
@@ -8,6 +8,7 @@ import (
"regexp"
"strings"
"sync"
"sync/atomic"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/report"
@@ -87,6 +88,8 @@ type Detector struct {
// report-related settings.
ReportPath string
Reporter report.Reporter
TotalBytes uint64
}
// Fragment contains the data to be scanned
@@ -94,6 +97,8 @@ type Fragment struct {
// Raw is the raw content of the fragment
Raw string
Bytes []byte
// FilePath is the path to the file if applicable
FilePath string
SymlinkFile string
@@ -178,6 +183,11 @@ func (d *Detector) DetectString(content string) []report.Finding {
// Detect scans the given fragment and returns a list of findings
func (d *Detector) Detect(fragment Fragment) []report.Finding {
if fragment.Bytes == nil {
atomic.AddUint64(&d.TotalBytes, uint64(len(fragment.Raw)))
}
atomic.AddUint64(&d.TotalBytes, uint64(len(fragment.Bytes)))
var findings []report.Finding
// check if filepath is allowed
+2 -1
View File
@@ -110,11 +110,12 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
}
// Count the number of newlines in this chunk
chunk := string(peekBuf.Bytes())
chunk := peekBuf.String()
linesInChunk := strings.Count(chunk, "\n")
totalLines += linesInChunk
fragment := Fragment{
Raw: chunk,
Bytes: peekBuf.Bytes(),
FilePath: pa.Path,
}
if pa.Symlink != "" {