From d984aa860005d79841080e8f4e2ef2c5eb058f8c Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> Date: Wed, 28 Aug 2013 14:26:17 -0400 Subject: [PATCH] [ #14268 ] daemon: Fix a race hash collision when creating new accounts too fast --- daemon/src/managerimpl.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 133b89ae60..5b929e70c5 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -2465,9 +2465,14 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) /** @todo Deal with both the accountMap_ and the Configuration */ std::stringstream accountID; + std::string accountList(preferences.getAccountOrder()); accountID << "Account:" << time(NULL); std::string newAccountID(accountID.str()); + while (accountList.find(newAccountID) != std::string::npos) { + newAccountID += "1"; + } + // Get the type std::string accountType; @@ -2500,9 +2505,8 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) newAccount->setAccountDetails(details); - // Add the newly created account in the account order list - std::string accountList(preferences.getAccountOrder()); + // Add the newly created account in the account order list newAccountID += "/"; if (not accountList.empty()) { // Prepend the new account @@ -2521,7 +2525,7 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) client_.getConfigurationManager()->accountsChanged(); - return accountID.str(); + return newAccountID; } void ManagerImpl::removeAccount(const std::string& accountID) -- GitLab