Skip to content

Commit

Permalink
pkg/vcs: relax check on git hash length
Browse files Browse the repository at this point in the history
We've seen 15 and 17 char hashes already.
And 14 wasn't initially in the list, but somebody used it.
Relax the check to 8..40 chars.
  • Loading branch information
dvyukov committed Jan 10, 2019
1 parent 7835524 commit da53282
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 2 additions & 6 deletions pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ func CheckBranch(branch string) bool {
}

func CheckCommitHash(hash string) bool {
if !gitHashRe.MatchString(hash) {
return false
}
ln := len(hash)
return ln == 8 || ln == 10 || ln == 12 || ln == 14 || ln == 16 || ln == 20 || ln == 40
return gitHashRe.MatchString(hash)
}

func runSandboxed(dir, command string, args ...string) ([]byte, error) {
Expand All @@ -157,7 +153,7 @@ var (
// nolint: lll
gitRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)://[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[0-9]+)?/[a-zA-Z0-9-_./]+\.git(/)?$`)
gitBranchRe = regexp.MustCompile("^[a-zA-Z0-9-_/.]{2,200}$")
gitHashRe = regexp.MustCompile("^[a-f0-9]+$")
gitHashRe = regexp.MustCompile("^[a-f0-9]{8,40}$")
releaseTagRe = regexp.MustCompile(`^v([0-9]+).([0-9]+)(?:\.([0-9]+))?$`)
ccRes = []*regexp.Regexp{
regexp.MustCompile(`^Reviewed\-.*: (.*)$`),
Expand Down
7 changes: 5 additions & 2 deletions pkg/vcs/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ func TestCheckCommitHash(t *testing.T) {
testPredicate(t, CheckCommitHash, map[string]bool{
"ff12bea91c22bba93d3ffc3034d813d686bc7eeb": true, // 40
"eae05cb0aaeae05cb0aa": true, // 20
"449dd6984d0eaabbc": true, // 17
"449dd6984d0eaabb": true, // 16
"a4983672f9ca4c": true, // 14
"449dd6984d0e": true, // 12
"eae05cb0aab": true, // 11
"eae05cb0aa": true, // 10
"eae05cb0": true, // 8
"": false,
"aa": false,
"eae05cb0aab": false,
"xxxxxxxx": false,
"eae05cb": false,
"ff12bea91c22bba93d3ffc3034d813d686bc7eebb": false,
"xxxxxxxx": false,
})
}

Expand Down

0 comments on commit da53282

Please sign in to comment.