Bug 1225800 - only import items that have valid URLs, r=MattN a=ritu
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 10 Dec 2015 12:27:52 -0500
changeset 310469 fc1f9e0e37f244e44b1d2f9e69e905155a73c959
parent 310468 25659c961f356fed0d43601f208f54d50c844296
child 310470 c71c57675de497e79f236d8e19a91430c2faab40
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, ritu
bugs1225800
milestone45.0a2
Bug 1225800 - only import items that have valid URLs, r=MattN a=ritu
browser/components/migration/MSMigrationUtils.jsm
--- a/browser/components/migration/MSMigrationUtils.jsm
+++ b/browser/components/migration/MSMigrationUtils.jsm
@@ -8,17 +8,16 @@ this.EXPORTED_SYMBOLS = ["MSMigrationUti
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 Cu.import("resource://gre/modules/AppConstants.jsm");
 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']);
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry",
                                   "resource://gre/modules/WindowsRegistry.jsm");
@@ -270,19 +269,19 @@ CtypesVaultHelpers.prototype = {
  *
  * @param aHost
  *        The host to check.
  * @return whether aHost is an IP address.
  */
 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;
 }
 
 var gEdgeDir;
 function getEdgeLocalDataFolder() {
   if (gEdgeDir) {
     return gEdgeDir.clone();
   }
@@ -509,17 +508,17 @@ Cookies.prototype = {
       }
     }
     return this.__cookiesFolders = folders.length ? folders : null;
   },
 
   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];
       for (let folder of folders) {
         let entries = folder.directoryEntries;
         while (entries.hasMoreElements()) {
           let entry = entries.getNext().QueryInterface(Ci.nsIFile);
           // Skip eventual bogus entries.
@@ -787,22 +786,31 @@ WindowsVaultFormPasswords.prototype = {
         throw new Error("Unable to enumerate Vault items: " + error);
       }
       for (let j = 0; j < itemCount.value; j++) {
         try {
           // if it's not an ie/edge password, skip it
           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;
           error = ctypesVaultHelpers._functions.VaultGetItem(vault,
                                                              item.contents.schemaId.address(),
                                                              item.contents.pResourceElement,
                                                              item.contents.pIdentityElement, null,
                                                              0, 0, credential.address());
@@ -819,17 +827,17 @@ WindowsVaultFormPasswords.prototype = {
                          fileTimeToSecondsSinceEpoch(item.contents.highLastModified,
                                                      item.contents.lowLastModified) * 1000;
           } catch (ex) {
             // Ignore exceptions in the dates and just create the login for right now.
           }
           // create a new login
           let login = {
             username, password,
-            hostname: NetUtil.newURI(url).prePath,
+            hostname: realURL.prePath,
             timeCreated: creation,
           };
           LoginHelper.maybeImportLogin(login);
 
           // close current item
           error = ctypesVaultHelpers._functions.VaultFree(credential);
           if (error == FREE_CLOSE_FAILED) {
             throw new Error("Unable to free item: " + error);