From b43b1ea6a92c3afd532c7ca8eadcfc631b4eaf80 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Sun, 18 Jan 2004 23:51:27 +0000 Subject: [PATCH] Bug 228270 - Fix problem where UTF8 sequences in the password file were being re-encoded as UTF8 (as if from UTF16) when the password file is read in. r=darin, sr=bzbarsky --- .../passwordmgr/base/nsPasswordManager.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/toolkit/components/passwordmgr/base/nsPasswordManager.cpp b/toolkit/components/passwordmgr/base/nsPasswordManager.cpp index 0fbdf99c00a..b0d91f9cc62 100644 --- a/toolkit/components/passwordmgr/base/nsPasswordManager.cpp +++ b/toolkit/components/passwordmgr/base/nsPasswordManager.cpp @@ -1333,6 +1333,7 @@ nsPasswordManager::ReadSignonFile() // Read the header nsAutoString buffer; + nsCAutoString utf8Buffer; PRBool moreData = PR_FALSE; nsresult rv = lineStream->ReadLine(buffer, &moreData); if (NS_FAILED(rv)) @@ -1354,17 +1355,23 @@ nsPasswordManager::ReadSignonFile() if (NS_FAILED(rv)) return; + // |buffer| will contain UTF-8 encoded characters, so move it into + // a narrow string so we can manipulate it. If NS_ReadLine is ever + // fixed to handle character encoding, this code should be cleaned up. + + utf8Buffer.AssignWithConversion(buffer); + switch (state) { case STATE_REJECT: - if (buffer.Equals(NS_LITERAL_STRING("."))) + if (utf8Buffer.Equals(NS_LITERAL_CSTRING("."))) state = STATE_REALM; else - mRejectTable.Put(NS_ConvertUCS2toUTF8(buffer), 1); + mRejectTable.Put(utf8Buffer, 1); break; case STATE_REALM: - realm.Assign(NS_ConvertUCS2toUTF8(buffer)); + realm.Assign(utf8Buffer); state = STATE_USERFIELD; break; @@ -1375,12 +1382,12 @@ nsPasswordManager::ReadSignonFile() AddSignonData(realm, entry); // If the line is a ., we've reached the end of this realm's entries. - if (buffer.Equals(NS_LITERAL_STRING("."))) { + if (utf8Buffer.Equals(NS_LITERAL_CSTRING("."))) { entry = nsnull; state = STATE_REALM; } else { entry = new SignonDataEntry(); - entry->userField.Assign(buffer); + CopyUTF8toUTF16(utf8Buffer, entry->userField); state = STATE_USERVALUE; } @@ -1389,7 +1396,7 @@ nsPasswordManager::ReadSignonFile() case STATE_USERVALUE: NS_ASSERTION(entry, "bad state"); - entry->userValue.Assign(buffer); + CopyUTF8toUTF16(utf8Buffer, entry->userValue); state = STATE_PASSFIELD; break; @@ -1398,7 +1405,8 @@ nsPasswordManager::ReadSignonFile() NS_ASSERTION(entry, "bad state"); // Strip off the leading "*" character - entry->passField.Assign(Substring(buffer, 1, buffer.Length() - 1)); + CopyUTF8toUTF16(Substring(utf8Buffer, 1, utf8Buffer.Length() - 1), + entry->passField); state = STATE_PASSVALUE; break; @@ -1406,7 +1414,7 @@ nsPasswordManager::ReadSignonFile() case STATE_PASSVALUE: NS_ASSERTION(entry, "bad state"); - entry->passValue.Assign(buffer); + CopyUTF8toUTF16(utf8Buffer, entry->passValue); state = STATE_USERFIELD; break;