From fe8c6271f2e5cdd30e939cb078f19afe8aef7e33 Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Mon, 1 Oct 2018 22:44:25 -0500 Subject: [PATCH] panic plan (#99) --- CHANGELOG.md | 4 ++++ main.go | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b52e0e0..894b563e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +1.6.1 +----- +- Recover from panic when diffing + 1.6.0 ----- - Default maximum goroutines spawned is number of cores your cpu run with. See benchmarks in wiki. diff --git a/main.go b/main.go index ec4bc85c..e7379a00 100644 --- a/main.go +++ b/main.go @@ -119,7 +119,7 @@ type Config struct { } const defaultGithubURL = "https://api.github.com/" -const version = "1.6.0" +const version = "1.6.1" const defaultConfig = ` title = "gitleaks config" # add regexes to the regex table @@ -393,6 +393,14 @@ func auditRef(repo Repo, ref *plumbing.Reference, commitWg *sync.WaitGroup, comm filePath string skipFile bool ) + defer func() { + <-semaphore + commitChan <- leaks + if r := recover(); r != nil { + log.Warnf("recoverying from panic on commit %s, likely large diff causing panic", c.Hash.String()) + } + }() + if prevCommit == nil { t, _ := c.Tree() files := t.Files() @@ -406,16 +414,12 @@ func auditRef(repo Repo, ref *plumbing.Reference, commitWg *sync.WaitGroup, comm }) if err != nil { log.Warnf("problem generating diff for commit: %s\n", c.Hash.String()) - <-semaphore - commitChan <- leaks return } } else { patch, err := c.Patch(prevCommit) if err != nil { log.Warnf("problem generating patch for commit: %s\n", c.Hash.String()) - <-semaphore - commitChan <- leaks return } for _, f := range patch.FilePatches() { @@ -445,8 +449,6 @@ func auditRef(repo Repo, ref *plumbing.Reference, commitWg *sync.WaitGroup, comm } } } - <-semaphore - commitChan <- leaks }(c, prevCommit) prevCommit = c return nil