From 9fe02c43ca309179ed2820500f743e7ba7c63d5a Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 11 Mar 2016 10:45:09 -0500 Subject: [PATCH] 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. --- waddrmgr/manager.go | 4 ++++ waddrmgr/manager_test.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/waddrmgr/manager.go b/waddrmgr/manager.go index 49f210b..dee041f 100644 --- a/waddrmgr/manager.go +++ b/waddrmgr/manager.go @@ -1711,6 +1711,10 @@ func (m *Manager) LastInternalAddress(account uint32) (ManagedAddress, error) { // ValidateAccountName validates the given account name and returns an error, if any. func ValidateAccountName(name string) error { + if name == "" { + str := "accounts may not be named the empty string" + return managerError(ErrInvalidAccount, str, nil) + } if isReservedAccountName(name) { str := "reserved account name" return managerError(ErrInvalidAccount, str, nil) diff --git a/waddrmgr/manager_test.go b/waddrmgr/manager_test.go index 0d79a18..1d66aa3 100644 --- a/waddrmgr/manager_test.go +++ b/waddrmgr/manager_test.go @@ -1138,6 +1138,12 @@ func testNewAccount(tc *testContext) bool { return false } // 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 _, err = tc.manager.NewAccount(testName) wantErrCode = waddrmgr.ErrInvalidAccount