Skip to content

Commit 57773c0

Browse files
authored
fix: resolve clone failure when HEAD file exists in repository (#13)
add -- separator to git show commands to prevent command injection
1 parent fbe73e5 commit 57773c0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

image/git-init/git/git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
185185
return fmt.Errorf("error parsing %s after fetching refspec %s", checkoutParam, spec.Refspec)
186186
}
187187

188-
if _, err := run(logger, "", "checkout", "-f", checkoutParam); err != nil {
188+
if _, err := run(logger, "", "checkout", "-f", checkoutParam, "--"); err != nil {
189189
return err
190190
}
191191

@@ -208,15 +208,15 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
208208

209209
// ShowCommit calls "git show ..." to get the commit SHA for the given revision
210210
func ShowCommit(logger *zap.SugaredLogger, revision, path string) (string, error) {
211-
output, err := run(logger, path, "show", "-q", "--pretty=format:%H", revision)
211+
output, err := run(logger, path, "show", "-q", "--pretty=format:%H", revision, "--")
212212
if err != nil {
213213
return "", err
214214
}
215215
return strings.TrimSuffix(output, "\n"), nil
216216
}
217217

218218
func showRef(logger *zap.SugaredLogger, revision, path string) (string, error) {
219-
output, err := run(logger, path, "show", "-q", "--pretty=format:%D", revision)
219+
output, err := run(logger, path, "show", "-q", "--pretty=format:%D", revision, "--")
220220
if err != nil {
221221
return "", err
222222
}

0 commit comments

Comments
 (0)