-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add length check for the return string #1420
Conversation
models/pull.go
Outdated
@@ -508,7 +508,7 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) { | |||
[]string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()}, | |||
"git", "rev-list", "--ancestry-path", "--merges", "--reverse", cmd) | |||
|
|||
if err != nil { | |||
if err != nil || len(mergeCommit) != 40 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err == nil && len(mergeCommit) != 40 {
err = errors.New("...")
}
if err != nil {
return ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done.
models/pull.go
Outdated
@@ -507,7 +507,9 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) { | |||
mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID), | |||
[]string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()}, | |||
"git", "rev-list", "--ancestry-path", "--merges", "--reverse", cmd) | |||
|
|||
if err == nil && len(mergeCommit) != 40 { | |||
err = fmt.Errorf("git rev-list --ancestry-path --merges --reverse: unexpected length of output (got:%d bytes)", len(mergeCommit)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print the mergeCommit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
LGTM |
LGTM |
Without the check, it could lead to out-of-bound panic if the return string is shorter than expected.