mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 05:04:22 +01:00
feat: add warning for quoted --log-opts values (#1160)
Co-authored-by: Richard Gomez <richard@rbcrt.com>
This commit is contained in:
1 parent
7dc9ba40a7
commit
7f53b033fe
1 file changed
+17
-1
+17
-1
@@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,12 +17,27 @@ var ErrEncountered bool
|
|||||||
|
|
||||||
// GitLog returns a channel of gitdiff.File objects from the
|
// GitLog returns a channel of gitdiff.File objects from the
|
||||||
// git log -p command for the given source.
|
// git log -p command for the given source.
|
||||||
|
var quotedOptPattern = regexp.MustCompile(`^(?:"[^"]+"|'[^']+')$`)
|
||||||
func GitLog(source string, logOpts string) (<-chan *gitdiff.File, error) {
|
func GitLog(source string, logOpts string) (<-chan *gitdiff.File, error) {
|
||||||
sourceClean := filepath.Clean(source)
|
sourceClean := filepath.Clean(source)
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if logOpts != "" {
|
if logOpts != "" {
|
||||||
args := []string{"-C", sourceClean, "log", "-p", "-U0"}
|
args := []string{"-C", sourceClean, "log", "-p", "-U0"}
|
||||||
args = append(args, strings.Split(logOpts, " ")...)
|
|
||||||
|
// Ensure that the user-provided |logOpts| aren't wrapped in quotes.
|
||||||
|
// https://github.com/gitleaks/gitleaks/issues/1153
|
||||||
|
userArgs := strings.Split(logOpts, " ")
|
||||||
|
var quotedOpts []string
|
||||||
|
for _, element := range userArgs {
|
||||||
|
if quotedOptPattern.MatchString(element) {
|
||||||
|
quotedOpts = append(quotedOpts, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(quotedOpts) > 0 {
|
||||||
|
log.Warn().Msgf("the following `--log-opts` values may not work as expected: %v\n\tsee https://github.com/gitleaks/gitleaks/issues/1153 for more information", quotedOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, userArgs...)
|
||||||
cmd = exec.Command("git", args...)
|
cmd = exec.Command("git", args...)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command("git", "-C", sourceClean, "log", "-p", "-U0",
|
cmd = exec.Command("git", "-C", sourceClean, "log", "-p", "-U0",
|
||||||
|
|||||||
Reference in new issue
Block a user