Bug 457358 - need to reset UTF8 converter after it encounters invalid input (pwmgr problems in FF3.0.3). r=gavin, a1904=dveditz

git-svn-id: svn://10.0.0.236/trunk@254529 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dolske%mozilla.com
2008-10-03 23:49:14 +00:00
parent 5997fb44d1
commit 9e6713a1aa
7 changed files with 223 additions and 0 deletions

View File

@@ -84,6 +84,10 @@ LoginManagerStorage_legacy.prototype = {
return this.__utfConverter;
},
_utfConverterReset : function() {
this.__utfConverter = null;
},
__profileDir: null, // nsIFile for the user's profile dir
get _profileDir() {
if (!this.__profileDir) {
@@ -854,6 +858,7 @@ LoginManagerStorage_legacy.prototype = {
line.value = this._utfConverter.ConvertToUnicode(line.value);
} catch (e) {
this.log("Bad UTF8 conversion: " + line.value);
this._utfConverterReset();
}
switch (parseState) {
@@ -1295,6 +1300,9 @@ LoginManagerStorage_legacy.prototype = {
this.log("Failed to decrypt string: " + cipherText +
" (" + e.name + ")");
// In the unlikely event the converter threw, reset it.
this._utfConverterReset();
// If the user clicks Cancel, we get NS_ERROR_NOT_AVAILABLE.
// If the cipherText is bad / wrong key, we get NS_ERROR_FAILURE
// Wrong passwords are handled by the decoderRing reprompting;

View File

@@ -0,0 +1,10 @@
#2e
.
https://bugzilla.mozilla.org (Accès reservé)
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X
*
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR
---
.

View File

@@ -0,0 +1,10 @@
#2e
.
https://bugzilla.mozilla.org
Accè
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X
*pass
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR
https://bugzilla.mozilla.org
---
.

View File

@@ -0,0 +1,10 @@
#2e
.
https://bugzilla.mozilla.org
u-Accè
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X
*p-Accè
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR
https://bugzilla.mozilla.org
---
.

View File

@@ -0,0 +1,10 @@
#2e
.
https://bugzilla.mozilla.org (Accè)
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X
*
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR
---
.

View File

@@ -0,0 +1,18 @@
#2e
.
https://www.google.com
un
MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECAcH36OqRDPBBAj4u1kKe2oefQ==
*pw
MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECDG4MxIBIm3IBAjLrxoeWcW5eg==
https://www.google.com
---
.
https://bugzilla.mozilla.org (extra user test)
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X
*
MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR
---
.

View File

@@ -570,6 +570,163 @@ LoginTest.initStorage(storage, OUTDIR, "output-454708.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
/*
* ---------------------- Bug 457358 ----------------------
* need to reset UTF8 converter after it encounters invalid input
* (pwmgr problems in FF3.0.3)
*/
/* ========== 16 ========== */
testnum++;
testdesc = "ensure UTF8 converter isn't left in bad state."
var utfRealm = "Acc" +
String.fromCharCode(0xe8) +
"s reserv" +
String.fromCharCode(0xe9);
bad8User.init("https://bugzilla.mozilla.org", null, utfRealm,
"dummydude", "itsasecret", "", "");
LoginTest.initStorage(storage,
INDIR, "signons-457358-1.txt",
OUTDIR, "output-457358-1.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
// The output file should contain valid UTF8 now, but the resulting
// JS string value remains the same.
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-1.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
/* ========== 17 ========== */
testnum++;
testdesc = "ensure UTF8 converter isn't left in bad state."
// The username field here is "Acc" + String.fromCharCode(0xe8), but the last
// character is invalid UTF8 -- it's the beginning of a multibyte sequence,
// but at the end of the input. The unicode converter silently truncates the
// string, and will throw when we feed it the next chunk of input (the
// encrypted username)
//
// Test for an expected login -- everthing fine except for the truncated field
// name (which we don't use anyway)
bad8User.init("https://bugzilla.mozilla.org", "https://bugzilla.mozilla.org", null,
"dummydude", "itsasecret", "Acc", "pass");
LoginTest.initStorage(storage,
INDIR, "signons-457358-2.txt",
OUTDIR, "output-457358-2.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
// The output file should contain valid UTF8 now, but the resulting
// JS string value remains the same.
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-2.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
/* ========== 18 ========== */
testnum++;
testdesc = "ensure UTF8 converter isn't left in bad state."
// As with previous test, but triggered with both field names.
bad8User.init("https://bugzilla.mozilla.org", "https://bugzilla.mozilla.org", null,
"dummydude", "itsasecret", "u-Acc", "p-Acc");
LoginTest.initStorage(storage,
INDIR, "signons-457358-3.txt",
OUTDIR, "output-457358-3.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
// The output file should contain valid UTF8 now, but the resulting
// JS string value remains the same.
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-3.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
/* ========== 19 ========== */
testnum++;
testdesc = "ensure UTF8 converter isn't left in bad state."
// Last character in the realm, this time. Not trunated, because the
// "http://site.com (realm)" format means there's always a trailing character,
// so the conversino throws.
bad8User.init("https://bugzilla.mozilla.org", null, "Acc" + String.fromCharCode(0xe8),
"dummydude", "itsasecret", "", "");
LoginTest.initStorage(storage,
INDIR, "signons-457358-4.txt",
OUTDIR, "output-457358-4.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
// The output file should contain valid UTF8 now, but the resulting
// JS string value remains the same.
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-4.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
/* ========== 20 ========== */
testnum++;
testdesc = "ensure UTF8 converter isn't left in bad state."
// Like last test, but try adding and removing a login too.
bad8User.init("https://bugzilla.mozilla.org", null, "Acc" + String.fromCharCode(0xe8),
"dummydude", "itsasecret", "", "");
LoginTest.initStorage(storage,
INDIR, "signons-457358-4.txt",
OUTDIR, "output-457358-4b.txt");
var anotherUser = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
anotherUser.init("http://mozilla.org", null,
String.fromCharCode(0xe8) + "xtra user " + String.fromCharCode(0x0163) + "est",
"dummydude", "itsasecret", "", "");
storage.addLogin(anotherUser);
LoginTest.checkStorageData(storage, [], [bad8User, anotherUser]);
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-4b.txt");
LoginTest.checkStorageData(storage, [], [bad8User, anotherUser]);
storage.removeLogin(anotherUser);
LoginTest.checkStorageData(storage, [], [bad8User]);
testdesc = "[flush and reload for verification 2]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-4b.txt");
LoginTest.checkStorageData(storage, [], [bad8User]);
/* ========== 21 ========== */
testnum++;
testdesc = "ensure UTF8 converter isn't left in bad state."
// The first login's username (plaintext) is invalid UTF8. It's handled as a
// bad decryption so we don't see the login, but make sure the other login in
// the file is ok.
// This is the first login:
//bad8User.init("https://www.google.com", "https://www.google.com", null,
// "Acc" + String.fromCharCode(0xe8) + "ss", "passw", "un", "pw");
anotherUser.init("https://bugzilla.mozilla.org", null, "extra user test",
"dummydude", "itsasecret", "", "");
LoginTest.initStorage(storage,
INDIR, "signons-457358-5.txt",
OUTDIR, "output-457358-5.txt");
LoginTest.checkStorageData(storage, [], [anotherUser]);
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-457358-5.txt");
LoginTest.checkStorageData(storage, [], [anotherUser]);
/* ========== end ========== */