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

Fix NPE on try to get tag reference via API #18245

Merged
merged 4 commits into from
Jan 12, 2022

Conversation

6543
Copy link
Member

@6543 6543 commented Jan 12, 2022

In current situation, you need to add the gitRepo into tag, but this is not always posible as it's an unexported field. so if you try to get a tag via api it will cause a 500. this fix it.

fix:

2022/01/12 00:13:46 ...common/middleware.go:70:1() [E] PANIC: runtime error: invalid memory address or nil pointer dereference
	/usr/lib/go/src/runtime/panic.go:221 (0x44dca6)
		panicmem: panic(memoryError)
	/usr/lib/go/src/runtime/signal_unix.go:735 (0x44dc76)
		sigpanic: panicmem()
	/home/user/gitea/modules/git/repo_commit_nogogit.go:71 (0xac4ed1)
		(*Repository).getCommit: wr, rd, cancel := repo.CatFileBatch(repo.Ctx)
	/home/user/gitea/modules/git/tag.go:30 (0xad384d)
		(*Tag).Commit: return tag.repo.getCommit(tag.Object)
	/home/user/gitea/modules/git/repo_tree_nogogit.go:37 (0xad381c)
		(*Repository).getTree: commit, err := tag.Commit()
	/home/user/gitea/modules/git/repo_tree_nogogit.go:85 (0xad3f44)
		(*Repository).GetTree: return repo.getTree(id)
	/home/user/gitea/services/repository/files/tree.go:25 (0x1b88257)
		GetTreeBySHA: gitTree, err := gitRepo.GetTree(sha)
	/home/user/gitea/routers/api/v1/repo/tree.go:63 (0x1c66b78)
		GetTree: if tree, err := files_service.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
	/home/user/gitea/modules/web/route.go:80 (0x1b5ff26)
		Wrap.func1: t(ctx)
	/usr/lib/go/src/net/http/server.go:2047 (0x77948e)
		HandlerFunc.ServeHTTP: f(w, r)
	/home/user/gitea/modules/context/api.go:436 (0x13805af)
		RepoRefForAPI.func1: next.ServeHTTP(w, req)
	/usr/lib/go/src/net/http/server.go:2047 (0x77948e)
		HandlerFunc.ServeHTTP: f(w, r)
	/home/user/gitea/modules/web/route.go:95 (0x1b600a5)

@6543 6543 added modifies/api This PR adds API routes or modifies them issue/regression Indicates a previously functioning feature or behavior that has broken or regressed after a change labels Jan 12, 2022
@6543 6543 added this to the 1.16.0 milestone Jan 12, 2022
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 12, 2022
@6543 6543 requested a review from zeripath January 12, 2022 00:29
@codecov-commenter
Copy link

codecov-commenter commented Jan 12, 2022

Codecov Report

Merging #18245 (7c4934c) into main (67d7388) will increase coverage by 0.01%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #18245      +/-   ##
==========================================
+ Coverage   45.63%   45.65%   +0.01%     
==========================================
  Files         830      830              
  Lines       92024    92021       -3     
==========================================
+ Hits        41993    42010      +17     
+ Misses      43289    43270      -19     
+ Partials     6742     6741       -1     
Impacted Files Coverage Δ
modules/git/repo_tag.go 61.60% <ø> (-0.61%) ⬇️
modules/git/repo_tree_nogogit.go 49.01% <0.00%> (ø)
modules/git/repo_commit_nogogit.go 59.34% <100.00%> (-0.45%) ⬇️
modules/git/tag.go 84.31% <100.00%> (ø)
modules/repository/repo.go 47.84% <100.00%> (ø)
routers/api/v1/repo/tag.go 56.25% <100.00%> (ø)
services/repository/push.go 53.05% <100.00%> (ø)
modules/queue/workerpool.go 50.00% <0.00%> (-0.77%) ⬇️
models/repo_list.go 76.62% <0.00%> (-0.60%) ⬇️
models/issue_comment.go 54.51% <0.00%> (+0.28%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67d7388...7c4934c. Read the comment docs.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 12, 2022
@lunny
Copy link
Member

lunny commented Jan 12, 2022

How about remove the repo field from tag?

@6543
Copy link
Member Author

6543 commented Jan 12, 2022

done

@GiteaBot GiteaBot 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 Jan 12, 2022
@zeripath zeripath merged commit ff00b86 into go-gitea:main Jan 12, 2022
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 13, 2022
* giteaoffical/main:
  Fix documents for development and bug report (go-gitea#18249)
  Add/update SMTP auth providers via cli (go-gitea#18197)
  Fix NPE on try to get tag reference via API (go-gitea#18245)
  Fix update user bug (go-gitea#18250)
@6543 6543 deleted the fix-npe-no-repo branch January 13, 2022 07:39
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/regression Indicates a previously functioning feature or behavior that has broken or regressed after a change lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants