Bug 347752 - Crash [@ MSVCR80.dll] when using nsIProperties service get method with null argumentp=Alfred Kayser <alfredkayser@nl.ibm.com>r=darin, sr=dougt
authorasqueella@gmail.com
Sun, 13 May 2007 09:48:39 -0700
changeset 1409 f18d934ac5eba03f6d6710cd00bb5bedb0026bb6
parent 1408 1efff74d7cbc1b6762b518233ef452a48257106d
child 1410 ef4ab8a1998291864d8320a1d718486985b6a7a5
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs347752
milestone1.9a5pre
Bug 347752 - Crash [@ MSVCR80.dll] when using nsIProperties service get method with null argumentp=Alfred Kayser <alfredkayser@nl.ibm.com>r=darin, sr=dougt
xpcom/ds/nsProperties.cpp
xpcom/io/nsDirectoryService.cpp
--- a/xpcom/ds/nsProperties.cpp
+++ b/xpcom/ds/nsProperties.cpp
@@ -44,43 +44,51 @@
 NS_IMPL_AGGREGATED(nsProperties)
 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties)
     NS_INTERFACE_MAP_ENTRY(nsIProperties)
 NS_INTERFACE_MAP_END
 
 NS_IMETHODIMP
 nsProperties::Get(const char* prop, const nsIID & uuid, void* *result)
 {
+    NS_ENSURE_ARG(prop);
+
     nsCOMPtr<nsISupports> value;
     if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
         return NS_ERROR_FAILURE;
     }
     return (value) ? value->QueryInterface(uuid, result) : NS_ERROR_NO_INTERFACE;
 }
 
 NS_IMETHODIMP
 nsProperties::Set(const char* prop, nsISupports* value)
 {
+    NS_ENSURE_ARG(prop);
+
     return Put(prop, value) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsProperties::Undefine(const char* prop)
 {
+    NS_ENSURE_ARG(prop);
+
     nsCOMPtr<nsISupports> value;
     if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value)))
         return NS_ERROR_FAILURE;
 
     Remove(prop);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProperties::Has(const char* prop, PRBool *result)
 {
+    NS_ENSURE_ARG(prop);
+
     nsCOMPtr<nsISupports> value;
     *result = nsProperties_HashBase::Get(prop,
                                          getter_AddRefs(value));
     return NS_OK;
 }
 
 struct GetKeysEnumData
 {
@@ -103,20 +111,22 @@ GetKeysEnumerate(const char *key, nsISup
 
     gkedp->next++;
     return PL_DHASH_NEXT;
 }
 
 NS_IMETHODIMP 
 nsProperties::GetKeys(PRUint32 *count, char ***keys)
 {
+    NS_ENSURE_ARG(count);
+    NS_ENSURE_ARG(keys);
+
     PRUint32 n = Count();
     char ** k = (char **) nsMemory::Alloc(n * sizeof(char *));
-    if (!k)
-        return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(k, NS_ERROR_OUT_OF_MEMORY);
 
     GetKeysEnumData gked;
     gked.keys = k;
     gked.next = 0;
     gked.res = NS_OK;
 
     EnumerateRead(GetKeysEnumerate, &gked);
 
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -525,16 +525,18 @@ nsDirectoryService::~nsDirectoryService(
 }
 
 NS_IMPL_THREADSAFE_ISUPPORTS4(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
 
 
 NS_IMETHODIMP
 nsDirectoryService::Undefine(const char* prop)
 {
+    NS_ENSURE_ARG(prop);
+
     nsCStringKey key(prop);
     if (!mHashtable.Exists(&key))
         return NS_ERROR_FAILURE;
 
     mHashtable.Remove (&key);
     return NS_OK;
  }
 
@@ -603,16 +605,18 @@ static PRBool FindProviderFile(nsISuppor
   }
 
   return PR_TRUE;
 }
 
 NS_IMETHODIMP
 nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result)
 {
+    NS_ENSURE_ARG(prop);
+
     nsCStringKey key(prop);
     
     nsCOMPtr<nsISupports> value = dont_AddRef(mHashtable.Get(&key));
     
     if (value)
     {
         nsCOMPtr<nsIFile> cloneFile;
         nsCOMPtr<nsIFile> cachedFile = do_QueryInterface(value);
@@ -651,16 +655,18 @@ nsDirectoryService::Get(const char* prop
     }
 
     return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsDirectoryService::Set(const char* prop, nsISupports* value)
 {
+    NS_ENSURE_ARG(prop);
+
     nsCStringKey key(prop);
     if (mHashtable.Exists(&key) || value == nsnull)
         return NS_ERROR_FAILURE;
 
     nsCOMPtr<nsIFile> ourFile;
     value->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(ourFile));
     if (ourFile)
     {
@@ -672,16 +678,18 @@ nsDirectoryService::Set(const char* prop
     }
 
     return NS_ERROR_FAILURE;   
 }
 
 NS_IMETHODIMP
 nsDirectoryService::Has(const char *prop, PRBool *_retval)
 {
+    NS_ENSURE_ARG(prop);
+
     *_retval = PR_FALSE;
     nsCOMPtr<nsIFile> value;
     nsresult rv = Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(value));
     if (NS_FAILED(rv))
         return NS_OK;
     
     if (value)
     {