-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-57q7-rxqq-7vgp
Use a safer method to locate the `git` executable (a simpler approach)
- Loading branch information
Showing
4 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package git | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/cli/safeexec" | ||
) | ||
|
||
// findGitBin finds the `git` binary in PATH that should be used by | ||
// the rest of `git-sizer`. It uses `safeexec` to find the executable, | ||
// because on Windows, `exec.Cmd` looks not only in PATH, but also in | ||
// the current directory. This is a potential risk if the repository | ||
// being scanned is hostile and non-bare because it might possibly | ||
// contain an executable file named `git`. | ||
func findGitBin() (string, error) { | ||
gitBin, err := safeexec.LookPath("git") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
gitBin, err = filepath.Abs(gitBin) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return gitBin, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters