Disallow naming accounts the empty string.

This change only prevents creating new accounts with the empty name or
renaming an existing account to one.  Any accounts in the DB that are
already named the empty string are left untouched (and should be
renamed to something meaningful by the user).

Fixes #369.
This commit is contained in:
Josh Rickmar 2016-03-11 10:45:09 -05:00
parent cee0411a2e
commit 9fe02c43ca
2 changed files with 10 additions and 0 deletions

View file

@ -1711,6 +1711,10 @@ func (m *Manager) LastInternalAddress(account uint32) (ManagedAddress, error) {
// ValidateAccountName validates the given account name and returns an error, if any. // ValidateAccountName validates the given account name and returns an error, if any.
func ValidateAccountName(name string) error { func ValidateAccountName(name string) error {
if name == "" {
str := "accounts may not be named the empty string"
return managerError(ErrInvalidAccount, str, nil)
}
if isReservedAccountName(name) { if isReservedAccountName(name) {
str := "reserved account name" str := "reserved account name"
return managerError(ErrInvalidAccount, str, nil) return managerError(ErrInvalidAccount, str, nil)

View file

@ -1138,6 +1138,12 @@ func testNewAccount(tc *testContext) bool {
return false return false
} }
// Test account name validation // Test account name validation
testName = "" // Empty account names are not allowed
_, err = tc.manager.NewAccount(testName)
wantErrCode = waddrmgr.ErrInvalidAccount
if !checkManagerError(tc.t, testName, err, wantErrCode) {
return false
}
testName = "imported" // A reserved account name testName = "imported" // A reserved account name
_, err = tc.manager.NewAccount(testName) _, err = tc.manager.NewAccount(testName)
wantErrCode = waddrmgr.ErrInvalidAccount wantErrCode = waddrmgr.ErrInvalidAccount