Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitleaks exits with exit code 0 when ambiguous argument to log-opts are provided #722

Closed
JoostVoskuil opened this issue Nov 30, 2021 · 7 comments · Fixed by #726, gitleaks/go-gitdiff#6 or #1250
Labels
bug Something isn't working

Comments

@JoostVoskuil
Copy link
Contributor

Describe the bug
Gitleaks exits with exit code 0 when ambiguous argument to log-opts are provided

To Reproduce
Run Gitleaks with log-opts that triggers an error from git log

Expected behavior
When error occurs I would expect exit code 1

** Logging**
8:47AM ERR fatal: ambiguous argument '18ee779d989c28192f5d439a91bcbbd3bf11dac2^..ffc5f83a4f995ed146c27fa32227ddfff251f282': unknown revision or path not in the working tree.
8:47AM ERR Use '--' to separate paths from revisions, like this:
8:47AM ERR 'git [...] -- [...]'
8:47AM INF no leaks found
8:47AM INF scan completed in 30.9416ms

Basic Info (please complete the following information):

  • OS:Osx Monterey
  • Gitleaks Version: 8.0.4
@JoostVoskuil JoostVoskuil added the bug Something isn't working label Nov 30, 2021
@zricethezav
Copy link
Collaborator

I'm not able to reproduce this behavior:

➜  ~/code/gitleaks (master) ./gitleaks detect --source=. --log-opts="18ee779d989c28192f5d439a91bcbbd3bf11dac2^..ffc5f83a4f995ed146c27fa32227ddfff251f282"

    ○
    │╲
    │ ○
    ○ ░
    ░    gitleaks

8:23AM ERR fatal: ambiguous argument '18ee779d989c28192f5d439a91bcbbd3bf11dac2^..ffc5f83a4f995ed146c27fa32227ddfff251f282': unknown revision or path not in the working tree.
8:23AM ERR Use '--' to separate paths from revisions, like this:
8:23AM ERR 'git <command> [<revision>...] -- [<file>...]'
➜  ~/code/gitleaks (master) echo $?
1
➜  ~/code/gitleaks (master)

This chunk of code is responsible for catching errors coming from git https://github.com/zricethezav/gitleaks/blob/master/git/git.go#L73-L85

I suppose what could be happening is the goroutine that continues the main execution finishes before the error can be scanned.

@zricethezav
Copy link
Collaborator

zricethezav commented Nov 30, 2021

Doing a little more testing and I'm realizing there is no reason to open a goroutine for streaming errors. The error checking should happen once at the beginning and that's it.

Just kidding, stdout is blocked if I remove the goroutine invocation. A simple hack would be to add a sleep timer for like 100 ms which would give the stderr scanner enough time to check for errors. I think I'll introduce that

@zricethezav
Copy link
Collaborator

@JoostVoskuil please try v8.0.6 and see if this is still an issue

@JoostVoskuil
Copy link
Contributor Author

Awesome, can't reproduce this anymore. You are really fast @zricethezav , can't keep up haha

@savely-krasovsky
Copy link
Contributor

@zricethezav maybe we should just use channel to sync instead of using time.Sleep hack?

@zricethezav
Copy link
Collaborator

@L11r that would be ideal! Once upon a time I tried to implement that but failed. Happy to accept a community PR if someone wants to give it a shot

@savely-krasovsky
Copy link
Contributor

@zricethezav I've prepared a draft PR: #1250! Also would be nice if you review those ones: #1242 and #1249

zricethezav pushed a commit that referenced this issue Aug 22, 2023
* refactor: fix #722 properly

* fix(deps): update go-gitdiff to v0.9.0

* refactor: second attempt

* refactor: better git package api

* fix: add comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants