From 9e6713a1aa560192710f8f7df94e57352344433e Mon Sep 17 00:00:00 2001 From: "dolske%mozilla.com" Date: Fri, 3 Oct 2008 23:49:14 +0000 Subject: [PATCH] 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 --- .../passwordmgr/src/storage-Legacy.js | 8 + .../test/unit/data/signons-457358-1.txt | 10 ++ .../test/unit/data/signons-457358-2.txt | 10 ++ .../test/unit/data/signons-457358-3.txt | 10 ++ .../test/unit/data/signons-457358-4.txt | 10 ++ .../test/unit/data/signons-457358-5.txt | 18 ++ .../test/unit/test_storage_legacy_3.js | 157 ++++++++++++++++++ 7 files changed, 223 insertions(+) create mode 100644 mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-1.txt create mode 100644 mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-2.txt create mode 100644 mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-3.txt create mode 100644 mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-4.txt create mode 100644 mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-5.txt diff --git a/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js b/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js index b0ffcdbda04..481fcc3f45b 100644 --- a/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js +++ b/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js @@ -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; diff --git a/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-1.txt b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-1.txt new file mode 100644 index 00000000000..5491537e995 --- /dev/null +++ b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-1.txt @@ -0,0 +1,10 @@ +#2e +. +https://bugzilla.mozilla.org (Accès reservé) + +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +* +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR + +--- +. diff --git a/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-2.txt b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-2.txt new file mode 100644 index 00000000000..253a7fae19a --- /dev/null +++ b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-2.txt @@ -0,0 +1,10 @@ +#2e +. +https://bugzilla.mozilla.org +Accè +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*pass +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR +https://bugzilla.mozilla.org +--- +. diff --git a/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-3.txt b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-3.txt new file mode 100644 index 00000000000..b53898dbcdb --- /dev/null +++ b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-3.txt @@ -0,0 +1,10 @@ +#2e +. +https://bugzilla.mozilla.org +u-Accè +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*p-Accè +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR +https://bugzilla.mozilla.org +--- +. diff --git a/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-4.txt b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-4.txt new file mode 100644 index 00000000000..779c678900c --- /dev/null +++ b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-4.txt @@ -0,0 +1,10 @@ +#2e +. +https://bugzilla.mozilla.org (Accè) + +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +* +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR + +--- +. diff --git a/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-5.txt b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-5.txt new file mode 100644 index 00000000000..15e57a3f72a --- /dev/null +++ b/mozilla/toolkit/components/passwordmgr/test/unit/data/signons-457358-5.txt @@ -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 + +--- +. diff --git a/mozilla/toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js b/mozilla/toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js index bf3e7d985d6..c25aa270bfa 100644 --- a/mozilla/toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js +++ b/mozilla/toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js @@ -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 ========== */