mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-26 19:30:55 +01:00
* Start Files Source
* Keep cmd the same for now
* Get tests to pass
* s.MaxTargetMegaBytes -> s.MaxFileSize
* Tweak some log messages & use q semgroup for files
* Just call yield inside the semgroup
* Refactor a check and revert some log lines
* Move mg && misc tuning
* Add `make profile`
(Benchmark results are only added if tools are installed)
Example output:
```
========================================================================
generating profile data
------------------------------------------------------------------------
- mode: dir
benchmark:
tool: hyperfine
path: profile/1748019612/dir/benchmark.json
results:
mean: 1.12852930166
stddev: 0.12163775966037399
median: 1.07242928416
user: 3.9699382799999996
system: 0.04382341999999999
min: 1.03207673016
max: 1.3913475181600001
profile:
- mode: cpu
path: profile/1748019612/dir/cpu.pprof
view: go tool pprof -http=localhost: ./gitleaks profile/1748019612/dir/cpu.pprof
- mode: mem
path: profile/1748019612/dir/mem.pprof
view: go tool pprof -http=localhost: ./gitleaks profile/1748019612/dir/mem.pprof
- mode: trace
path: profile/1748019612/dir/trace.out
view: go tool trace profile/1748019612/dir/trace.out
- mode: git
...snip...
```
* Archive support for File based sources
* Move Git to Source interface
* Scan archives in git
* Misc linter fixes
* Exclude certain diffs: --diff-filter=tuxdb
* Add git archives tests
* Log error instead of fatal
* Fix spacing in test config
* Refine source comments/wording
* Make MB conversions more readable
* Format cmd
* Adjust DetectSource logging
* MiB -> MB in logs
* Add testdata/repos/archives/dotGit/refs/.gitkeep
Without it the refs folder gets deleted and the
and then it isn't detected as a git repo ¯\_(ツ)_/¯
So then the test starts scanning the whole gitleaks
repo instead :D
* Handle finding links for archives
* Working on archive depth
* Fixes from failfast test
* cmd max-archive-depth
* added comments, fixed warnings
* removed test print
* Update README.md
* Set archive depth for DetectFiles
* Tweak logs & pass max archive for readers
* Pass ctx to Fragments
* Add make lint target and address some issues
* Fix compat issue
* Report path in fragment errors
* Apply PR suggestions & misc changes
- Update blobReader.Close() to discard the buffer
- Misc logger issues & uses
- Tweak .golangci.yaml to default to none
- Discard remaining blobReader data on close
- Undo a De Morgan's Law suggestion (and disable QF1001)
* Add http mode for diagnostics
gitleaks --diagnostics=http ...
-----
From the net/http/pprof docs:
Use the pprof tool to look at the heap profile:
```
go tool pprof http://localhost:6060/debug/pprof/heap
```
Or to look at a 30-second CPU profile:
```
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
```
Or to look at the goroutine blocking profile, after calling runtime.SetBlockProfileRate in your program:
```
go tool pprof http://localhost:6060/debug/pprof/block
```
Or to look at the holders of contended mutexes, after calling runtime.SetMutexProfileFraction in your program:
```
go tool pprof http://localhost:6060/debug/pprof/mutex
```
(For more info see https://pkg.go.dev/net/http/pprof)
---------
Co-authored-by: Alex Layne <alayne@redhat.com>
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package detect
|
|
|
|
// Location represents a location in a file
|
|
type Location struct {
|
|
startLine int
|
|
endLine int
|
|
startColumn int
|
|
endColumn int
|
|
startLineIndex int
|
|
endLineIndex int
|
|
}
|
|
|
|
func location(newlineIndices [][]int, raw string, matchIndex []int) Location {
|
|
var (
|
|
prevNewLine int
|
|
location Location
|
|
lineSet bool
|
|
_lineNum int
|
|
)
|
|
|
|
start := matchIndex[0]
|
|
end := matchIndex[1]
|
|
|
|
// default startLineIndex to 0
|
|
location.startLineIndex = 0
|
|
|
|
// Fixes: https://github.com/zricethezav/gitleaks/issues/1037
|
|
// When a fragment does NOT have any newlines, a default "newline"
|
|
// will be counted to make the subsequent location calculation logic work
|
|
// for fragments will no newlines.
|
|
if len(newlineIndices) == 0 {
|
|
newlineIndices = [][]int{
|
|
{len(raw), len(raw) + 1},
|
|
}
|
|
}
|
|
|
|
for lineNum, pair := range newlineIndices {
|
|
_lineNum = lineNum
|
|
newLineByteIndex := pair[0]
|
|
if prevNewLine <= start && start < newLineByteIndex {
|
|
lineSet = true
|
|
location.startLine = lineNum
|
|
location.endLine = lineNum
|
|
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
|
|
location.startLineIndex = prevNewLine
|
|
location.endLineIndex = newLineByteIndex
|
|
}
|
|
if prevNewLine < end && end <= newLineByteIndex {
|
|
location.endLine = lineNum
|
|
location.endColumn = (end - prevNewLine)
|
|
location.endLineIndex = newLineByteIndex
|
|
}
|
|
|
|
prevNewLine = pair[0]
|
|
}
|
|
|
|
if !lineSet {
|
|
// if lines never get set then that means the secret is most likely
|
|
// on the last line of the diff output and the diff output does not have
|
|
// a newline
|
|
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
|
|
location.endColumn = (end - prevNewLine)
|
|
location.startLine = _lineNum + 1
|
|
location.endLine = _lineNum + 1
|
|
|
|
// search for new line byte index
|
|
i := 0
|
|
for end+i < len(raw) {
|
|
if raw[end+i] == '\n' {
|
|
break
|
|
}
|
|
if raw[end+i] == '\r' {
|
|
break
|
|
}
|
|
i++
|
|
}
|
|
location.endLineIndex = end + i
|
|
}
|
|
return location
|
|
}
|