diff options
author | zeripath <art27@cantab.net> | 2021-09-30 20:31:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 21:31:02 +0200 |
commit | 206ea10b45e8659eb3227239d3012b20dbb24231 (patch) | |
tree | 7629d37ca57165410a76f9adce6ddb60bd3e357b /routers/web | |
parent | 3bbdce26012d02d3b5082f8774ce432ad9c2990b (diff) | |
download | gitea-206ea10b45e8659eb3227239d3012b20dbb24231.tar.gz gitea-206ea10b45e8659eb3227239d3012b20dbb24231.zip |
Prevent NPE on invalid diff (#17197)
* Prevent NPE on invalid diff
If ParseCompareInfo returns a nil compare info the defer function needs to ensure
that it does not attempt to close the HeadGitRepo.
Fix #17193
Signed-off-by: Andrew Thornton <art27@cantab.net>
* add TEST
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/compare.go | 2 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 71ca4df93e..556a6218a6 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -635,7 +635,7 @@ func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (bool func CompareDiff(ctx *context.Context) { ci := ParseCompareInfo(ctx) defer func() { - if ci.HeadGitRepo != nil { + if ci != nil && ci.HeadGitRepo != nil { ci.HeadGitRepo.Close() } }() diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 1b15ea9a79..9c9cf0f21d 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1043,7 +1043,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { ci := ParseCompareInfo(ctx) defer func() { - if ci.HeadGitRepo != nil { + if ci != nil && ci.HeadGitRepo != nil { ci.HeadGitRepo.Close() } }() |