Skip to content
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

Merged
merged 3 commits into from
Mar 31, 2017

Conversation

typeless
Copy link
Contributor

Without the check, it could lead to out-of-bound panic if the return string is shorter than expected.

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 {
Copy link
Member

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 ...
}

Copy link
Contributor Author

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print the mergeCommit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lunny lunny added this to the 1.2.0 milestone Mar 31, 2017
@lunny lunny added the type/bug label Mar 31, 2017
@lunny
Copy link
Member

lunny commented Mar 31, 2017

LGTM

@tboerger tboerger added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Mar 31, 2017
@appleboy
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 31, 2017
@appleboy appleboy merged commit 6a39250 into go-gitea:master Mar 31, 2017
@typeless typeless deleted the add-sanity-check branch April 3, 2019 04:59
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants