From 83b7c6e6018a5fda0ab87b4787fb51e6d785049b Mon Sep 17 00:00:00 2001 From: "morse%netscape.com" Date: Tue, 12 Mar 2002 21:19:03 +0000 Subject: [PATCH] bug 128948, crash in password manager, r=racham, sr=jag, a=asa git-svn-id: svn://10.0.0.236/trunk@116423 18797224-902f-48f8-a5cc-f745e15eee43 --- .../wallet/src/nsPasswordManager.cpp | 60 ++++++++++--------- .../base/util/nsMsgIncomingServer.cpp | 6 +- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/mozilla/extensions/wallet/src/nsPasswordManager.cpp b/mozilla/extensions/wallet/src/nsPasswordManager.cpp index 449cd080a61..3ec995ad990 100644 --- a/mozilla/extensions/wallet/src/nsPasswordManager.cpp +++ b/mozilla/extensions/wallet/src/nsPasswordManager.cpp @@ -220,40 +220,42 @@ nsPasswordManager::FindPasswordEntry(char **hostURI, PRUnichar **username, PRUni // Emumerate through password elements while (hasMoreElements) { rv = enumerator->GetNext(getter_AddRefs(passwordElem)); - if (NS_SUCCEEDED(rv) && passwordElem) { - // Get the server URI stored as host - nsXPIDLCString thisHostURI; - passwordElem->GetHost(getter_Copies(thisHostURI)); + if (NS_FAILED(rv)) { + return rv; // could not unlock the database + } - nsXPIDLString thisUsername; - passwordElem->GetUser(getter_Copies(thisUsername)); + // Get the server URI stored as host + nsXPIDLCString thisHostURI; + passwordElem->GetHost(getter_Copies(thisHostURI)); - nsXPIDLString thisPassword; - passwordElem->GetPassword(getter_Copies(thisPassword)); + nsXPIDLString thisUsername; + passwordElem->GetUser(getter_Copies(thisUsername)); - // Check if any of the params are null (set by getter_Copies as - // preparation for output parameters) and treat them wild card - // entry matches or if they match with current password element - // attribute values. - PRBool hostURIOK = !*hostURI || thisHostURI.Equals(*hostURI); - PRBool usernameOK = !*username || thisUsername.Equals(*username); - PRBool passwordOK = !*password || thisPassword.Equals(*password); + nsXPIDLString thisPassword; + passwordElem->GetPassword(getter_Copies(thisPassword)); - // If a password match is found based on given input params, - // fill in those params which are passed in as empty strings. - if (hostURIOK && usernameOK && passwordOK) - { - if (!*hostURI) { - *hostURI = ToNewCString(thisHostURI); - } - if (!*username) { - *username = ToNewUnicode(thisUsername); - } - if (!*password) { - *password = ToNewUnicode(thisPassword); - } - break; + // Check if any of the params are null (set by getter_Copies as + // preparation for output parameters) and treat them wild card + // entry matches or if they match with current password element + // attribute values. + PRBool hostURIOK = !*hostURI || thisHostURI.Equals(*hostURI); + PRBool usernameOK = !*username || thisUsername.Equals(*username); + PRBool passwordOK = !*password || thisPassword.Equals(*password); + + // If a password match is found based on given input params, + // fill in those params which are passed in as empty strings. + if (hostURIOK && usernameOK && passwordOK) + { + if (!*hostURI) { + *hostURI = ToNewCString(thisHostURI); } + if (!*username) { + *username = ToNewUnicode(thisUsername); + } + if (!*password) { + *password = ToNewUnicode(thisPassword); + } + break; } enumerator->HasMoreElements(&hasMoreElements); } diff --git a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp index e7af7dc7ba9..a119cc7f1de 100644 --- a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp @@ -1609,7 +1609,11 @@ nsMsgIncomingServer::GetIsAuthenticated(PRBool *isAuthenticated) // Get password entry corresponding to the host URI we are passing in. rv = passwordMgr->FindPasswordEntry(&hostURI, getter_Copies(userName), getter_Copies(password)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + // release hostURI + nsMemory::Free(hostURI); + return rv; + } // release hostURI nsMemory::Free(hostURI);