-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fix nil-dereference bug #1258
Conversation
@@ -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) |
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.
ctx.User
may be nil
, so this doesn't work
modules/context/repo.go
Outdated
@@ -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) |
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.
Maybe var userID int64
is better ?
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.
Sure, will update.
217b1e1
to
5dbc21e
Compare
LGTM |
LGTM |
if ctx.User != nil { | ||
userID = ctx.User.ID | ||
} | ||
mode, err := models.AccessLevel(userID, repo) |
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.
What happens if ctx.User is nil here ? What's the value of userID ? Is that value guaranteed to mean "anonymous user" ?
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.
Yes, userID=0
means anonymous user, see access.go: line 68
5dbc21e
to
99eb049
Compare
Rebased; the CI build wasn't running for some reason |
99eb049
to
17f403f
Compare
Fix bug introduced by #1247 where viewing a repository while not signed in a user causes a 500 (due to a nil pointer deference).