Reliably return an error from token.Parse.

We would sometimes return nil cast to an interface with no error,
which would cause the server to crash with a null dereference.
This commit is contained in:
Juliusz Chroboczek
2023-05-14 21:14:59 +02:00
parent dc8a78be32
commit 3c0dbf5e9b
4 changed files with 55 additions and 6 deletions
+4 -1
View File
@@ -55,11 +55,14 @@ func SetStatefulFilename(filename string) {
tokens.modTime = time.Time{}
}
func getStateful(token string) (Token, error) {
func getStateful(token string) (*Stateful, error) {
tokens.mu.Lock()
defer tokens.mu.Unlock()
err := tokens.load()
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
if tokens.tokens == nil {