Bug 1595059 - Prevent copying an address book card without a UID, and fix copying cards from one book to another; r+a=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 11 Nov 2019 15:39:37 +1300
changeset 37299 64d30069741e189b6ee137d566ad5dcfa2c4729a
parent 37298 8616fc3baa19eedff16ad5ae2d135b1904ba7c02
child 37300 a67ce4c2f2bc92c519b2e9b8ca65a8c337f1e0f2
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
bugs1595059
Bug 1595059 - Prevent copying an address book card without a UID, and fix copying cards from one book to another; r+a=mkmelin Special thanks to Prettier for causing this.
mailnews/addrbook/content/abDragDrop.js
mailnews/addrbook/jsaddrbook/AddrBookDirectory.jsm
--- a/mailnews/addrbook/content/abDragDrop.js
+++ b/mailnews/addrbook/content/abDragDrop.js
@@ -223,19 +223,23 @@ var abDirTreeObserver = {
 
     // The data contains the a string of "selected rows", eg.: "1,2".
     var rows = dataTransfer
       .getData("moz/abcard")
       .split(",")
       .map(j => parseInt(j, 10));
 
     for (var j = 0; j < rows.length; j++) {
-      if (gAbView.getCardFromRow(rows[j]).isMailList) {
+      let card = gAbView.getCardFromRow(rows[j]);
+      if (!card.UID) {
+        Cu.reportError(new Error("Card must have a UID to be dropped here."));
+        return false;
+      }
+      if (card.isMailList) {
         draggingMailList = true;
-        break;
       }
     }
 
     // The rest of the cases - allow cards for copy or move, but only allow
     // move of mailing lists if we're not going into another mailing list.
     if (
       draggingMailList &&
       (targetDirectory.isMailList ||
--- a/mailnews/addrbook/jsaddrbook/AddrBookDirectory.jsm
+++ b/mailnews/addrbook/jsaddrbook/AddrBookDirectory.jsm
@@ -812,20 +812,24 @@ AddrBookDirectoryInner.prototype = {
     // notification should be fired for each one. Let the list handle that.
     for (let list of this.childNodes) {
       list.deleteCards(cards);
     }
 
     deleteCardStatement.finalize();
   },
   dropCard(card, needToCopyCard) {
+    if (!card.UID) {
+      throw new Error("Card must have a UID to be added to this directory.");
+    }
+
     let newCard = new AddrBookCard();
     newCard.directoryId = this.uuid;
     newCard.localId = this._getNextCardId();
-    newCard._uid = needToCopyCard || card.UID || newUID();
+    newCard._uid = needToCopyCard ? newUID() : card.UID;
 
     let insertStatement = this._dbConnection.createStatement(
       "INSERT INTO cards (uid, localId) VALUES (:uid, :localId)"
     );
     insertStatement.params.uid = newCard.UID;
     insertStatement.params.localId = newCard.localId;
     insertStatement.execute();
     insertStatement.finalize();