Skip to content

Commit 2d3b52c

Browse files
authored
SessionUser protection against nil pointer dereference (#21358)
`SessionUser` should be protected against passing `sess` = `nil` to avoid ``` PANIC: runtime error: invalid memory address or nil pointer dereference ``` in https://github.com/go-gitea/gitea/pull/18452/files#diff-a215b82aadeb8b4c4632fcf31215dd421f804eb1c0137ec6721b980136e4442aR69 after upgrade from gitea v1.16 to v1.17. Related: #18452 Author-Change-Id: IB#1126459
1 parent b001812 commit 2d3b52c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

services/auth/session.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataSto
3939

4040
// SessionUser returns the user object corresponding to the "uid" session variable.
4141
func SessionUser(sess SessionStore) *user_model.User {
42+
if sess == nil {
43+
return nil
44+
}
45+
4246
// Get user ID
4347
uid := sess.Get("uid")
4448
if uid == nil {

0 commit comments

Comments
 (0)