From e1743f0fb6752ff7cb4246a1929a2e92581235e5 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Thu, 10 Dec 2015 12:27:52 -0500 Subject: [PATCH] Bug 1225800 - only import items that have valid URLs, r=MattN --HG-- extra : commitid : 1P2Spaxd6iT extra : rebase_source : 9e73392a354a02d2b65d5fa9e4906eee8600e6ac --- .../components/migration/MSMigrationUtils.jsm | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/browser/components/migration/MSMigrationUtils.jsm b/browser/components/migration/MSMigrationUtils.jsm index 7c30348166b1..0c7518357831 100644 --- a/browser/components/migration/MSMigrationUtils.jsm +++ b/browser/components/migration/MSMigrationUtils.jsm @@ -13,7 +13,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Task.jsm"); Cu.import("resource:///modules/MigrationUtils.jsm"); -Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/LoginHelper.jsm"); Cu.importGlobalProperties(['FileReader']); @@ -275,9 +274,9 @@ CtypesVaultHelpers.prototype = { function hostIsIPAddress(aHost) { try { Services.eTLD.getBaseDomainFromHost(aHost); - } catch (e if e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS) { - return true; - } catch (e) {} + } catch (e) { + return e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS; + } return false; } @@ -514,7 +513,7 @@ Cookies.prototype = { migrate(aCallback) { this.ctypesKernelHelpers = new CtypesKernelHelpers(); - let cookiesGenerator = (function genCookie() { + let cookiesGenerator = (function* genCookie() { let success = false; let folders = this._migrationType == MSMigrationUtils.MIGRATION_TYPE_EDGE ? this.__cookiesFolders : [this.__cookiesFolder]; @@ -792,12 +791,21 @@ WindowsVaultFormPasswords.prototype = { if (!_isIEOrEdgePassword(item.contents.schemaId.id)) { continue; } + let url = item.contents.pResourceElement.contents.itemValue.readString(); + let realURL; + try { + realURL = Services.io.newURI(url, null, null); + } catch (ex) { /* leave realURL as null */ } + if (!realURL || ["http", "https", "ftp"].indexOf(realURL.scheme) == -1) { + // Ignore items for non-URLs or URLs that aren't HTTP(S)/FTP + continue; + } + // if aOnlyCheckExists is set to true, the purpose of the call is to return true if there is at // least a password which is true in this case because a password was by now already found if (aOnlyCheckExists) { return true; } - let url = item.contents.pResourceElement.contents.itemValue.readString(); let username = item.contents.pIdentityElement.contents.itemValue.readString(); // the current login credential object let credential = new ctypesVaultHelpers._structs.VAULT_ELEMENT.ptr; @@ -824,7 +832,7 @@ WindowsVaultFormPasswords.prototype = { // create a new login let login = { username, password, - hostname: NetUtil.newURI(url).prePath, + hostname: realURL.prePath, timeCreated: creation, }; LoginHelper.maybeImportLogin(login);