Skip to content

Commit adac68d

Browse files
committed
SessionUser protection against nil pointer dereference
`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: go-gitea#18452 Author-Change-Id: IB#1126459
1 parent cbebcc1 commit adac68d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

services/auth/session.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 The Gitea Authors. All rights reserved.
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

@@ -30,6 +30,10 @@ func (s *Session) Name() string {
3030
// object for that uid.
3131
// Returns nil if there is no user uid stored in the session.
3232
func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
33+
if sess == nil {
34+
return nil
35+
}
36+
3337
user := SessionUser(sess)
3438
if user != nil {
3539
return user

0 commit comments

Comments
 (0)