Bug 280232 Search crashes on working with address book from sidebar [@ nsCSubstring::ReplacePrep ][@ nsCharTraits<char>::compareLowerCaseToASCIINullTerminated(char const*, unsigned int, char const*)] - try and workaround by protecting against recursive searches. r/sr=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Wed, 26 Aug 2009 08:02:50 +0100
changeset 3419 781e0426972f5ff40a92cb85d0ec16e9304cb44a
parent 3418 f3ef93ea58423a29e444c1dfa98d1f5f5dd391ab
child 3420 799490fea817ac6238d65d36878cfd4d2270c525
push idunknown
push userunknown
push dateunknown
bugs280232
Bug 280232 Search crashes on working with address book from sidebar [@ nsCSubstring::ReplacePrep ][@ nsCharTraits<char>::compareLowerCaseToASCIINullTerminated(char const*, unsigned int, char const*)] - try and workaround by protecting against recursive searches. r/sr=bienvenu
mailnews/addrbook/public/nsIAbDirectory.idl
mailnews/addrbook/src/nsAbDirProperty.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.h
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/addrbook/src/nsAbMDBDirectory.h
mailnews/addrbook/src/nsAbOSXDirectory.h
mailnews/addrbook/src/nsAbOSXDirectory.mm
mailnews/addrbook/src/nsAbOutlookDirectory.cpp
mailnews/addrbook/src/nsAbOutlookDirectory.h
--- a/mailnews/addrbook/public/nsIAbDirectory.idl
+++ b/mailnews/addrbook/public/nsIAbDirectory.idl
@@ -55,17 +55,17 @@ interface nsIMutableArray;
 #define kCollectedAddressbook      "history.mab"
 #define kCollectedAddressbookUri   "moz-abmdbdirectory://history.mab"
 
 #define kABFileName_PreviousSuffix ".na2" /* final v2 address book format */
 #define kABFileName_PreviousSuffixLen 4
 #define kABFileName_CurrentSuffix ".mab"  /* v3 address book extension */
 %}
 
-[scriptable, uuid(5ee48561-aff9-447c-802d-93384d524f53)]
+[scriptable, uuid(4b2ed38f-9420-4491-92d3-f6ef110f363a)]
 interface nsIAbDirectory : nsIAbCollection {
 
   /**
    * The chrome URI to use for bringing up a dialog to edit this directory.
    * When opening the dialog, use a JS argument of
    * {selectedDirectory: thisdir} where thisdir is this directory that you just
    * got the chrome URI from.
    */
@@ -103,16 +103,22 @@ interface nsIAbDirectory : nsIAbCollecti
   readonly attribute nsISimpleEnumerator childNodes;
 
   /**
    * Get the cards associated with the directory. This will return the cards
    * associated with the mailing lists too.
    */
   readonly attribute nsISimpleEnumerator childCards;
 
+  /**
+   * Returns true if this directory represents a query - i.e. the rdf resource
+   * was something like moz-abmdbdirectory://abook.mab?....
+   */
+  readonly attribute boolean isQuery;
+
   // Deletes either a mailing list or a top
   // level directory, which also updates the
   // preferences
   void deleteDirectory(in nsIAbDirectory directory);
 
   // Check if directory contains card
   // If the implementation is asynchronous the card
   // may not yet have arrived. If it is in the process
--- a/mailnews/addrbook/src/nsAbDirProperty.cpp
+++ b/mailnews/addrbook/src/nsAbDirProperty.cpp
@@ -247,16 +247,25 @@ NS_IMETHODIMP nsAbDirProperty::CopyMailL
   SetDescription(str);
 
   nsCOMPtr<nsIMutableArray> pAddressLists;
   srcList->GetAddressLists(getter_AddRefs(pAddressLists));
   SetAddressLists(pAddressLists);
   return NS_OK;
 }
 
+NS_IMETHODIMP nsAbDirProperty::GetIsQuery(PRBool *aResult)
+{
+  NS_ENSURE_ARG_POINTER(aResult);
+  // Mailing lists are not queries by default, individual directory types
+  // will override this.
+  *aResult = PR_FALSE;
+  return NS_OK;
+}
+
 // nsIAbDirectory NOT IMPLEMENTED methods
 
 NS_IMETHODIMP
 nsAbDirProperty::GetChildNodes(nsISimpleEnumerator **childList)
 { return NS_ERROR_NOT_IMPLEMENTED; }
 
 NS_IMETHODIMP
 nsAbDirProperty::GetChildCards(nsISimpleEnumerator **childCards)
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
@@ -192,16 +192,23 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChil
 
       rv = NS_NewEmptyEnumerator(result);
     }
 
     NS_ENSURE_SUCCESS(rv,rv);
     return rv;
 }
 
+NS_IMETHODIMP nsAbLDAPDirectory::GetIsQuery(PRBool *aResult)
+{
+  NS_ENSURE_ARG_POINTER(aResult);
+  *aResult = mIsQueryURI;
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsAbLDAPDirectory::HasCard(nsIAbCard* card, PRBool* hasCard)
 {
   nsresult rv = Initiate ();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Enter lock
   nsAutoLock lock (mLock);
 
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.h
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.h
@@ -66,16 +66,17 @@ public:
 
   NS_IMETHOD Init(const char *aUri);
 
   // nsIAbDirectory methods
   NS_IMETHOD GetPropertiesChromeURI(nsACString &aResult);
   NS_IMETHOD GetURI(nsACString &aURI);
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator* *result);
+  NS_IMETHOD GetIsQuery(PRBool *aResult);
   NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
   NS_IMETHOD GetSupportsMailingLists(PRBool *aSupportsMailingsLists);
   NS_IMETHOD GetReadOnly(PRBool *aReadOnly);
   NS_IMETHOD GetIsRemote(PRBool *aIsRemote);
   NS_IMETHOD GetIsSecure(PRBool *aIsRemote);
   NS_IMETHOD UseForAutocomplete(const nsACString &aIdentityKey, PRBool *aResult);
   NS_IMETHOD AddCard(nsIAbCard *aChildCard, nsIAbCard **aAddedCard);
   NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -453,16 +453,23 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChild
 
   if (NS_FAILED(rv) || !mDatabase)
     return rv;
 
   return m_IsMailList ? mDatabase->EnumerateListAddresses(this, result) :
                         mDatabase->EnumerateCards(this, result);
 }
 
+NS_IMETHODIMP nsAbMDBDirectory::GetIsQuery(PRBool *aResult)
+{
+  NS_ENSURE_ARG_POINTER(aResult);
+  *aResult = mIsQueryURI;
+  return NS_OK;
+}
+
 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)
@@ -940,16 +947,30 @@ NS_IMETHODIMP nsAbMDBDirectory::StartSea
   // Get the directory without the query
   nsCOMPtr<nsIRDFResource> resource;
   rv = gRDFService->GetResource(mURINoQuery, getter_AddRefs(resource));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // Bug 280232 - something was causing continuous loops in searching. Add a
+  // check here for the directory to search not being a query uri as well in
+  // the hopes that will at least break us out of the continuous loop even if
+  // we don't know how we got into it.
+  PRBool isQuery;
+  rv = directory->GetIsQuery(&isQuery);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (isQuery)
+  {
+    NS_ERROR("Attempting to search a directory within a search");
+    return NS_ERROR_FAILURE;
+  }
+
   // Initiate the proxy query with the no query directory
   nsCOMPtr<nsIAbDirectoryQueryProxy> queryProxy = 
       do_CreateInstance(NS_ABDIRECTORYQUERYPROXY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = queryProxy->Initiate();
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/mailnews/addrbook/src/nsAbMDBDirectory.h
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.h
@@ -84,16 +84,17 @@ public:
   NS_IMETHOD RemoveEmailAddressAt(PRUint32 aIndex);
   NS_IMETHOD AddDirectory(const char *uriName, nsIAbDirectory **childDir);
   NS_IMETHOD GetDatabaseFile(nsILocalFile **aResult);
   NS_IMETHOD GetDatabase(nsIAddrDatabase **aResult);
 
   // nsIAbDirectory methods:
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator* *result);
+  NS_IMETHOD GetIsQuery(PRBool *aResult);
   NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
   NS_IMETHOD DeleteCards(nsIArray *cards);
   NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
   NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
   NS_IMETHOD AddMailList(nsIAbDirectory *list);
   NS_IMETHOD AddCard(nsIAbCard *card, nsIAbCard **addedCard);
   NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
   NS_IMETHOD DropCard(nsIAbCard *card, PRBool needToCopyCard);
--- a/mailnews/addrbook/src/nsAbOSXDirectory.h
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.h
@@ -91,16 +91,17 @@ public:
     
     // nsAbDirectoryRDFResource method
     NS_IMETHOD Init(const char *aUri);
   
   // nsAbDirProperty methods
   NS_IMETHOD GetReadOnly(PRBool *aReadOnly);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards);
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
+  NS_IMETHOD GetIsQuery(PRBool *aResult);
   NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
   NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
   NS_IMETHOD GetURI(nsACString &aURI);
   NS_IMETHOD GetCardFromProperty(const char *aProperty,
                                  const nsACString &aValue,
                                  PRBool caseSensitive,
                                  nsIAbCard **aResult);
   NS_IMETHOD CardForEmailAddress(const nsACString &aEmailAddress,
--- a/mailnews/addrbook/src/nsAbOSXDirectory.mm
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.mm
@@ -836,16 +836,24 @@ nsAbOSXDirectory::GetChildCards(nsISimpl
   }
 
   // Not a search, so just return the appropriate list of items.
   return m_IsMailList ? NS_NewArrayEnumerator(aCards, m_AddressList) :
          NS_NewArrayEnumerator(aCards, mCardList);
 }
 
 NS_IMETHODIMP
+nsAbOSXDirectory::GetIsQuery(PRBool *aResult)
+{
+  NS_ENSURE_ARG_POINTER(aResult);
+  *aResult = mIsQueryURI;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsAbOSXDirectory::GetCardFromProperty(const char *aProperty,
                                       const nsACString &aValue,
                                       PRBool aCaseSensitive,
                                       nsIAbCard **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
   *aResult = nsnull;
--- a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp
@@ -245,16 +245,23 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetC
             }
             else
               NS_WARNING("Card wasn't stored");
         }
     }
     return retCode ;
 }
 
+NS_IMETHODIMP nsAbOutlookDirectory::GetIsQuery(PRBool *aResult)
+{
+  NS_ENSURE_ARG_POINTER(aResult);
+  *aResult = mIsQueryURI;
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
 {
     if (!aCard || !aHasCard) { return NS_ERROR_NULL_POINTER ; }
     *aHasCard = mCardList.Get(aCard, nsnull);
     return NS_OK ;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory)
--- a/mailnews/addrbook/src/nsAbOutlookDirectory.h
+++ b/mailnews/addrbook/src/nsAbOutlookDirectory.h
@@ -65,16 +65,17 @@ public:
   nsAbOutlookDirectory(void);
   virtual ~nsAbOutlookDirectory(void);
 	
 	// nsAbDirProperty methods
   NS_IMETHOD GetDirType(PRInt32 *aDirType);
   NS_IMETHOD GetURI(nsACString &aURI);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards);
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
+  NS_IMETHOD GetIsQuery(PRBool *aResult);
   NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
   NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
   NS_IMETHOD DeleteCards(nsIArray *aCardList);
   NS_IMETHOD DeleteDirectory(nsIAbDirectory *aDirectory);
   NS_IMETHOD AddCard(nsIAbCard *aData, nsIAbCard **addedCard);
   NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
   NS_IMETHOD DropCard(nsIAbCard *aData, PRBool needToCopyCard);
   NS_IMETHOD AddMailList(nsIAbDirectory *aMailList);