Crivaledaz / Mattermost-LDAP

This module provides an external LDAP authentication in Mattermost for the Team Edition (free).
MIT License
364 stars 71 forks source link

Runtime error : invalid memory address or nil pointer dereference #24

Closed tthdvd closed 5 years ago

tthdvd commented 6 years ago

I've installed the newest mattermost, and I got the following error, when I try to login with "gitlab" . I guess mattermost is missing some data from the oauth server response, but i couldn't figure it out.

Mattermost Version: 5.2.1 Database Schema Version: 5.2.0 Database: mysql

{"level":"error","ts":1535704341.1152675,"caller":"app/server.go:62","msg":"Please check the std error output for the stack trace"}
{"level":"error","ts":1535704341.1153526,"caller":"app/server.go:63","msg":"[runtime error: invalid memory address or nil pointer dereference]"}
goroutine 2568 [running]:
runtime/debug.Stack(0x0, 0x0, 0x1280980)
    /usr/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
    /usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.log(0x16fd760, 0xc420217f10, 0x16fd440, 0x2070a70, 0x1, 0xc420030ae0, 0x1, 0x1)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:89 +0x70
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP.func1(0x1709300, 0xc4223588c0, 0x16fd760, 0xc420217f10, 0x16fd440, 0x2070a70, 0x1)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:74 +0xe5
panic(0x1333ee0, 0x20141c0)
    /usr/local/go/src/runtime/panic.go:502 +0x229
github.com/mattermost/mattermost-server/model/gitlab.(*GitLabUser).IsValid(...)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:78
github.com/mattermost/mattermost-server/model/gitlab.(*GitLabProvider).GetUserFromJson(0x2070a70, 0x7f099a348060, 0xc4200309a0, 0x7f099a348060)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:95 +0x3a
github.com/mattermost/mattermost-server/app.(*App).CompleteSwitchWithOAuth(0xc42010c580, 0xc4205bd8cc, 0x6, 0x1705620, 0xc4200309a0, 0xc422189fe0, 0x11, 0x0, 0xc4212aa248)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/app/oauth.go:572 +0x100
github.com/mattermost/mattermost-server/app.(*App).CompleteOAuth(0xc42010c580, 0xc4205bd8cc, 0x6, 0x1705620, 0xc4200309a0, 0x0, 0x0, 0xc421689380, 0x0, 0x0)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/app/oauth.go:509 +0x42c
github.com/mattermost/mattermost-server/api4.completeOAuth(0xc422361b00, 0x1709300, 0xc4223588c0, 0xc422361a00)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/api4/oauth.go:486 +0x891
github.com/mattermost/mattermost-server/web.Handler.ServeHTTP(0xc42010c580, 0x15ab910, 0x0, 0x1709300, 0xc4223588c0, 0xc422361a00)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/web/handlers.go:131 +0x126d
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux.(*Router).ServeHTTP(0xc420217f10, 0x1709300, 0xc4223588c0, 0xc422361a00)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux/mux.go:162 +0xed
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP(0x16fd760, 0xc420217f10, 0x16fd440, 0x2070a70, 0x1, 0x1709300, 0xc4223588c0, 0xc422361800)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:78 +0xb9
net/http.serverHandler.ServeHTTP(0xc421de3110, 0x1709300, 0xc4223588c0, 0xc422361800)
    /usr/local/go/src/net/http/server.go:2694 +0xbc
net/http.(*conn).serve(0xc4215ab360, 0x170a400, 0xc421fb3780)
    /usr/local/go/src/net/http/server.go:1830 +0x651
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2795 +0x27b
{"level":"error","ts":1535704379.3484302,"caller":"app/server.go:62","msg":"Please check the std error output for the stack trace"}
{"level":"error","ts":1535704379.3486562,"caller":"app/server.go:63","msg":"[runtime error: invalid memory address or nil pointer dereference]"}
goroutine 2386 [running]:
runtime/debug.Stack(0x0, 0x0, 0x1280980)
    /usr/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
    /usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.log(0x16fd760, 0xc420217f10, 0x16fd440, 0x2070a70, 0x1, 0xc4202d9760, 0x1, 0x1)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:89 +0x70
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP.func1(0x1709300, 0xc4217d4700, 0x16fd760, 0xc420217f10, 0x16fd440, 0x2070a70, 0x1)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:74 +0xe5
panic(0x1333ee0, 0x20141c0)
    /usr/local/go/src/runtime/panic.go:502 +0x229
github.com/mattermost/mattermost-server/model/gitlab.(*GitLabUser).IsValid(...)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:78
github.com/mattermost/mattermost-server/model/gitlab.(*GitLabProvider).GetUserFromJson(0x2070a70, 0x7f099a348060, 0xc4202d9620, 0x7f099a348060)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:95 +0x3a
github.com/mattermost/mattermost-server/app.(*App).CompleteSwitchWithOAuth(0xc42010c580, 0xc4205bd68c, 0x6, 0x1705620, 0xc4202d9620, 0xc4223a7780, 0x11, 0x0, 0xc421d72488)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/app/oauth.go:572 +0x100
github.com/mattermost/mattermost-server/app.(*App).CompleteOAuth(0xc42010c580, 0xc4205bd68c, 0x6, 0x1705620, 0xc4202d9620, 0x0, 0x0, 0xc4215535c0, 0x0, 0x0)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/app/oauth.go:509 +0x42c
github.com/mattermost/mattermost-server/api4.completeOAuth(0xc4224b7600, 0x1709300, 0xc4217d4700, 0xc4224b7500)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/api4/oauth.go:486 +0x891
github.com/mattermost/mattermost-server/web.Handler.ServeHTTP(0xc42010c580, 0x15ab910, 0x0, 0x1709300, 0xc4217d4700, 0xc4224b7500)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/web/handlers.go:131 +0x126d
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux.(*Router).ServeHTTP(0xc420217f10, 0x1709300, 0xc4217d4700, 0xc4224b7500)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux/mux.go:162 +0xed
github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP(0x16fd760, 0xc420217f10, 0x16fd440, 0x2070a70, 0x1, 0x1709300, 0xc4217d4700, 0xc4224b7300)
    /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:78 +0xb9
net/http.serverHandler.ServeHTTP(0xc421de3110, 0x1709300, 0xc4217d4700, 0xc4224b7300)
    /usr/local/go/src/net/http/server.go:2694 +0xbc
net/http.(*conn).serve(0xc42294dae0, 0x170a400, 0xc42179e140)
    /usr/local/go/src/net/http/server.go:1830 +0x651
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2795 +0x27b

danielefranceschi commented 6 years ago

I have a (very) similar problem with mattermost 4.8: my stack trace is

github.com/mattermost/mattermost-server/model/gitlab.(*GitLabUser).IsValid(...)
        /var/lib/jenkins/jobs/msr/jobs/d/jobs/enterprise-release/workspace/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:78
github.com/mattermost/mattermost-server/model/gitlab.(*GitLabProvider).GetAuthDataFromJson(0x246aa78, 0x1d159e0, 0xc423812390, 0x6, 0xc42008b288)
        /var/lib/jenkins/jobs/msr/jobs/d/jobs/enterprise-release/workspace/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:109 +0x3a

from (*GitLabProvider).GetAuthDataFromJson while yours is from (*GitLabProvider).GetUserFromJson.

The root cause seems a null-pointer dereference in https://github.com/mattermost/mattermost-server/blob/release-5.2/model/gitlab/gitlab.go#L78, which means that https://github.com/mattermost/mattermost-server/blob/release-5.2/model/gitlab/gitlab.go#L60 (json decoding) is failing:

func gitLabUserFromJson(data io.Reader) *GitLabUser {
    decoder := json.NewDecoder(data)
    var glu GitLabUser
    err := decoder.Decode(&glu)
    if err == nil {
        return &glu
    } else {
        return nil
    }
}

Actually I'm not a gopher, so my first best guess was the missing login field in json decoding. But after modifying resource.php adding a login entry, the error did not disappear.

danielefranceschi commented 6 years ago

Commit 502ae7ecb4ca9ffd93b558185f575f64407ad95a works with mattermost 4.8.0 and 5.2.0.

gharms80 commented 5 years ago

Two test servers here. One with Mattermost 5.2.2 and one with 5.5.2. Same problem on both servers. Saw this https://github.com/mattermost/mattermost-server/issues/9960 and patch in 5.5.2 https://github.com/mattermost/mattermost-server/commit/0e31263320bd4c547de430e9291e91fe635c71d0 . Seems there is something wrong. Anyone? How to fix this?

Log of Mattermost 5.5.2:

{"level":"error","ts":1547454283.9044385,"caller":"app/server.go:60","msg":"Please check the std error output for the stack trace"} {"level":"error","ts":1547454283.9044843,"caller":"app/server.go:61","msg":"runtime error: invalid memory address or nil pointer dereference"} goroutine 3713 [running]: runtime/debug.Stack(0xc002aefe90, 0xe65a04, 0xc00333d280) /usr/local/go/src/runtime/debug/stack.go:24 +0xa7 runtime/debug.PrintStack() /usr/local/go/src/runtime/debug/stack.go:16 +0x22 github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.log(0x1572440, 0xc0001e2d90, 0x1572180, 0x20a0700, 0x1, 0xc002a5d770, 0x1, 0x1) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:89 +0x71 github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP.func1(0x157d320, 0xc0019aec40, 0x1572440, 0xc0001e2d90, 0x1572180, 0x20a0700, 0x1) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:74 +0xda panic(0x118eae0, 0x2044030) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/mattermost/mattermost-server/model/gitlab.(*GitLabUser).IsValid(...) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:78 github.com/mattermost/mattermost-server/model/gitlab.(*GitLabProvider).GetUserFromJson(0x20a0700, 0x7ff710627f20, 0xc00336db00, 0x6) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/model/gitlab/gitlab.go:95 +0x3a github.com/mattermost/mattermost-server/app.(*App).CreateOAuthUser(0xc0000e8580, 0xc0000d446c, 0x6, 0x7ff710627f20, 0xc00336db00, 0x0, 0x0, 0xc000231568, 0xc000231560) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/app/user.go:262 +0x142 github.com/mattermost/mattermost-server/app.(*App).CompleteOAuth(0xc0000e8580, 0xc0000d446c, 0x6, 0x1578480, 0xc00336db00, 0x0, 0x0, 0xc002c177a0, 0x0, 0x0) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/app/oauth.go:505 +0x1e5 github.com/mattermost/mattermost-server/api4.completeOAuth(0xc002573300, 0x157d320, 0xc0019aec40, 0xc002573200) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/api4/oauth.go:501 +0xc4d github.com/mattermost/mattermost-server/web.Handler.ServeHTTP(0xc0000e8580, 0x13a9de0, 0x0, 0x157d320, 0xc0019aec40, 0xc002573200) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/web/handlers.go:131 +0x1343 github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux.(*Router).ServeHTTP(0xc0001e2d90, 0x157d320, 0xc0019aec40, 0xc002573200) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux/mux.go:162 +0xf1 github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP(0x1572440, 0xc0001e2d90, 0x1572180, 0x20a0700, 0x1, 0x157d320, 0xc0019aec40, 0xc002573000) /home/ubuntu/jenkins/workspace/msr/mattermost-platform-release/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:78 +0xb0 net/http.serverHandler.ServeHTTP(0xc002bfaf70, 0x157d320, 0xc0019aec40, 0xc002573000) /usr/local/go/src/net/http/server.go:2741 +0xab net/http.(*conn).serve(0xc003939c20, 0x157e1e0, 0xc0039a1780) /usr/local/go/src/net/http/server.go:1847 +0x646 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2851 +0x2f5

hege-li commented 5 years ago

5.7.1 works fine here after I uncommented resource.php to use this "old" version..

    // Below is the old version, still consistent with Mattermost before version 4.4
    $resp = array("name" => $data['cn'],"username" => $user,"id" => $assoc_id,"state" => "active","email" => $data['mail']);
gharms80 commented 5 years ago

Installed 5.7.1, does not work here :-(

gharms80 commented 5 years ago

@hekeli: It's really working at your installation with Mattermost 5.7.1? Can you share your configuration files with me? Can't get it working with 5.7.1 or 5.8.0. I have it installed on Debian 8 here.

hege-li commented 5 years ago

@gharms80 Yes latest master version of Mattermost-LDAP and Mattermost 5.7.1 open source edition. Nothing needed except changing $resp described above, then it won't die on nil pointer. RedHat 7.

Crivaledaz commented 5 years ago

This issue should be resolved by the pull request #26, so I close it. Feel free to reopen it if you still have the error.

Thank you for your feedbacks,