Bug 1523904 - Return NS_ERROR_FAILURE when setting UID on a read-only address book. r=mkmelin,BenB a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 08 Feb 2019 15:08:08 +1300
changeset 34325 7759b93fc8dd484d38a2596e65f86ac1516f0a40
parent 34324 9378f2d586b07b4adef8802297ffa2bbf4dd3363
child 34326 96ed115c265a0ade97dd3840a89202ea828d71f9
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersmkmelin, BenB, jorgk
bugs1523904
Bug 1523904 - Return NS_ERROR_FAILURE when setting UID on a read-only address book. r=mkmelin,BenB a=jorgk
mailnews/addrbook/src/nsAbCardProperty.cpp
--- a/mailnews/addrbook/src/nsAbCardProperty.cpp
+++ b/mailnews/addrbook/src/nsAbCardProperty.cpp
@@ -381,17 +381,28 @@ NS_IMETHODIMP nsAbCardProperty::SetUID(c
 
   nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr <nsIAbDirectory> directory = nullptr;
   rv = abManager->GetDirectoryFromId(directoryId, getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return directory ? directory->ModifyCard(this) : NS_OK;
+  if (!directory) {
+    return NS_OK;
+  }
+
+  bool readOnly;
+  rv = directory->GetReadOnly(&readOnly);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (readOnly) {
+    return NS_ERROR_FAILURE;
+  }
+  return directory->ModifyCard(this);
 }
 
 NS_IMETHODIMP nsAbCardProperty::GetFirstName(nsAString &aString)
 {
   nsresult rv = GetPropertyAsAString(kFirstNameProperty, aString);
   if (rv == NS_ERROR_NOT_AVAILABLE)
   {
     aString.Truncate();