ipn: make LoadPrefs return os.ErrNotExist when reading corrupted files
It appears some users have corrupted pref.conf files. Have LoadPrefs treat these files as non-existent. This way tailscale will make user login, and not crash. Fixes #954 Signed-off-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
2c48b4ee14
commit
72e082aaf5
@@ -5,6 +5,7 @@
|
||||
package ipn
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -276,6 +277,9 @@ func LoadPrefs(filename string) (*Prefs, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadPrefs open: %w", err) // err includes path
|
||||
}
|
||||
if bytes.Contains(data, jsonEscapedZero) {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
p, err := PrefsFromBytes(data, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadPrefs(%q) decode: %w", filename, err)
|
||||
|
||||
Reference in New Issue
Block a user