Bug 448165 Mailnews crashes in [@ nsAbMDBDirectory::DeleteCards] if aCards is null. r=me,sr=bienvenu
authorJosh Geenen <joshgeenen+bugzilla@gmail.com>
Wed, 30 Jul 2008 13:53:21 -0700
changeset 46 427e30ec84584da1c47e013d6626db475abcea52
parent 45 8ec0e0de88b8cf06b6bd0edd3e10fb4f83c2e5d0
child 47 0ce42125210f9e700ef2d941085f8ab2804c944f
push idunknown
push userunknown
push dateunknown
reviewersme, bienvenu
bugs448165
Bug 448165 Mailnews crashes in [@ nsAbMDBDirectory::DeleteCards] if aCards is null. r=me,sr=bienvenu
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/addrbook/test/unit/test_bug_448165.js
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -455,16 +455,17 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChild
     return rv;
 
   return m_IsMailList ? mDatabase->EnumerateListAddresses(this, result) :
                         mDatabase->EnumerateCards(this, result);
 }
 
 NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsIArray *aCards)
 {
+  NS_ENSURE_ARG_POINTER(aCards);
   nsresult rv = NS_OK;
 
   if (mIsQueryURI) {
     // if this is a query, delete the cards from the directory (without the query)
     // before we do the delete, make this directory (which represents the search)
     // a listener on the database, so that it will get notified when the cards are deleted
     // after delete, remove this query as a listener.
     nsCOMPtr<nsIAddrDatabase> database;
new file mode 100644
--- /dev/null
+++ b/mailnews/addrbook/test/unit/test_bug_448165.js
@@ -0,0 +1,19 @@
+/**
+ * A simple test to check for a regression of bug 448165: Mailnews crashes in
+ * nsAbMDBDirectory::DeleteCards if aCards is null
+ */
+function run_test() {
+  // get the Address Book Manager service
+  var abManager = Cc["@mozilla.org/abmanager;1"].getService(Ci.nsIAbManager);
+  // get the Personal Address Book
+  var pab = abManager.getDirectory(kPABData.URI);
+  do_check_true(pab instanceof Ci.nsIAbDirectory);
+  try {
+    pab.deleteCards(null); // this should throw an error
+    do_throw("Error, deleteCards should throw an error when null is passed to it");
+  }
+  catch (e) {
+    // make sure the correct error message was thrown
+    do_check_neq(e.toString().indexOf("NS_ERROR_INVALID_POINTER"), -1);
+  }
+}