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:
Alex Brainman
2020-11-22 11:34:26 +11:00
committed by Brad Fitzpatrick
parent 2c48b4ee14
commit 72e082aaf5
2 changed files with 27 additions and 0 deletions
+4
View File
@@ -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)