2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-28 21:02:47 +00:00

Merge pull request #3811 from restic/fix-secret-string-crash

Don't crash if SecretString is uninitialized
This commit is contained in:
MichaelEischer 2022-07-02 19:56:36 +02:00 committed by GitHub
commit 7137034517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -13,12 +13,15 @@ func (s SecretString) GoString() string {
}
func (s SecretString) String() string {
if len(*s.s) == 0 {
if s.s == nil || len(*s.s) == 0 {
return ``
}
return `**redacted**`
}
func (s *SecretString) Unwrap() string {
if s.s == nil {
return ""
}
return *s.s
}

View File

@ -53,3 +53,11 @@ func TestSecretStringEmpty(t *testing.T) {
test.Equals(t, `""`, fmt.Sprintf("%#v", secret))
test.Equals(t, keyStr, secret.Unwrap())
}
func TestSecretStringDefault(t *testing.T) {
secretStruct := &secretTest{}
test.Equals(t, "", secretStruct.str.String())
test.Equals(t, `""`, secretStruct.str.GoString())
test.Equals(t, "", secretStruct.str.Unwrap())
}