|
@@ -25,6 +25,9 @@ import (
|
|
|
// After that, file chunks are created which are then inspected by InspectString()
|
|
// After that, file chunks are created which are then inspected by InspectString()
|
|
|
func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
|
func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
|
|
for _, f := range patch.FilePatches() {
|
|
for _, f := range patch.FilePatches() {
|
|
|
|
|
+ if repo.timeoutReached() {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
if f.IsBinary() {
|
|
if f.IsBinary() {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
@@ -119,6 +122,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
|
|
|
// an optimization would be to switch the regex from FindAllIndex to FindString
|
|
// an optimization would be to switch the regex from FindAllIndex to FindString
|
|
|
// since we are iterating on the lines if entropy rules exist...
|
|
// since we are iterating on the lines if entropy rules exist...
|
|
|
for _, line := range strings.Split(content, "\n") {
|
|
for _, line := range strings.Split(content, "\n") {
|
|
|
|
|
+ if repo.timeoutReached() {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
entropyTripped := trippedEntropy(line, rule)
|
|
entropyTripped := trippedEntropy(line, rule)
|
|
|
if entropyTripped && !ruleContainRegex(rule) {
|
|
if entropyTripped && !ruleContainRegex(rule) {
|
|
|
repo.Manager.SendLeaks(manager.Leak{
|
|
repo.Manager.SendLeaks(manager.Leak{
|
|
@@ -135,6 +141,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
|
|
|
File: filename,
|
|
File: filename,
|
|
|
})
|
|
})
|
|
|
} else if entropyTripped {
|
|
} else if entropyTripped {
|
|
|
|
|
+ if repo.timeoutReached() {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
// entropy has been tripped which means if there is a regex specified in the same
|
|
// entropy has been tripped which means if there is a regex specified in the same
|
|
|
// rule, we need to inspect the line for a regex match. In otherwords, the current rule has
|
|
// rule, we need to inspect the line for a regex match. In otherwords, the current rule has
|
|
|
// both entropy and regex set which work in combination. This helps narrow down false positives
|
|
// both entropy and regex set which work in combination. This helps narrow down false positives
|
|
@@ -179,6 +188,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
|
|
|
if rule.Regex.String() == "" {
|
|
if rule.Regex.String() == "" {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
+ if repo.timeoutReached() {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
start := time.Now()
|
|
start := time.Now()
|
|
|
locs := rule.Regex.FindAllIndex([]byte(content), -1)
|
|
locs := rule.Regex.FindAllIndex([]byte(content), -1)
|
|
|
if len(locs) != 0 {
|
|
if len(locs) != 0 {
|
|
@@ -255,7 +267,7 @@ func inspectCommit(c *object.Commit, repo *Repo) error {
|
|
|
|
|
|
|
|
err = fIter.ForEach(func(f *object.File) error {
|
|
err = fIter.ForEach(func(f *object.File) error {
|
|
|
bin, err := f.IsBinary()
|
|
bin, err := f.IsBinary()
|
|
|
- if bin {
|
|
|
|
|
|
|
+ if bin || repo.timeoutReached() {
|
|
|
return nil
|
|
return nil
|
|
|
} else if err != nil {
|
|
} else if err != nil {
|
|
|
return err
|
|
return err
|