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 nil-dereference bug #1258

Merged
merged 1 commit into from
Mar 16, 2017
Merged

Conversation

ethantkoenig
Copy link
Member

Fix bug introduced by #1247 where viewing a repository while not signed in a user causes a 500 (due to a nil pointer deference).

@lunny lunny added this to the 1.2.0 milestone Mar 15, 2017
@lunny lunny added the type/bug label Mar 15, 2017
@@ -219,7 +219,11 @@ func RepoAssignment(args ...bool) macaron.Handler {
if ctx.IsSigned && ctx.User.IsAdmin {
ctx.Repo.AccessMode = models.AccessModeOwner
} else {
mode, err := models.AccessLevel(ctx.User.ID, repo)
Copy link
Member Author

Choose a reason for hiding this comment

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

ctx.User may be nil, so this doesn't work

@@ -219,7 +219,11 @@ func RepoAssignment(args ...bool) macaron.Handler {
if ctx.IsSigned && ctx.User.IsAdmin {
ctx.Repo.AccessMode = models.AccessModeOwner
} else {
mode, err := models.AccessLevel(ctx.User.ID, repo)
userID := int64(0)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe var userID int64 is better ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will update.

@bkcsoft
Copy link
Member

bkcsoft commented Mar 15, 2017

LGTM

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

lunny commented Mar 15, 2017

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 15, 2017
if ctx.User != nil {
userID = ctx.User.ID
}
mode, err := models.AccessLevel(userID, repo)
Copy link
Member

Choose a reason for hiding this comment

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

What happens if ctx.User is nil here ? What's the value of userID ? Is that value guaranteed to mean "anonymous user" ?

Copy link
Member Author

@ethantkoenig ethantkoenig Mar 15, 2017

Choose a reason for hiding this comment

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

Yes, userID=0 means anonymous user, see access.go: line 68

@ethantkoenig
Copy link
Member Author

Rebased; the CI build wasn't running for some reason

@andreynering andreynering merged commit 43c5469 into go-gitea:master Mar 16, 2017
@ethantkoenig ethantkoenig deleted the fix/access branch March 16, 2017 02:29
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 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.

6 participants