Bug 590512 - Firefox 4.0b Crash [@ PL_DHashTableOperate | nsPrefBranch::GetBoolPref(char const*, int*) ]. r=dougt, a=final+

This commit is contained in:
Dan Witte 2010-10-07 14:00:17 -07:00
parent f01cf84dbe
commit 4af4661231
2 changed files with 63 additions and 13 deletions

View File

@ -143,7 +143,6 @@ NS_INTERFACE_MAP_END
NS_IMETHODIMP nsPrefBranch::GetRoot(char **aRoot)
{
NS_ENSURE_ARG_POINTER(aRoot);
mPrefRoot.Truncate(mPrefRootLength);
*aRoot = ToNewCString(mPrefRoot);
return NS_OK;
@ -151,6 +150,7 @@ NS_IMETHODIMP nsPrefBranch::GetRoot(char **aRoot)
NS_IMETHODIMP nsPrefBranch::GetPrefType(const char *aPrefName, PRInt32 *_retval)
{
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
*_retval = PREF_GetPrefType(pref);
return NS_OK;
@ -158,6 +158,7 @@ NS_IMETHODIMP nsPrefBranch::GetPrefType(const char *aPrefName, PRInt32 *_retval)
NS_IMETHODIMP nsPrefBranch::GetBoolPref(const char *aPrefName, PRBool *_retval)
{
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_GetBoolPref(pref, _retval, mIsDefault);
}
@ -171,12 +172,14 @@ NS_IMETHODIMP nsPrefBranch::SetBoolPref(const char *aPrefName, PRInt32 aValue)
}
#endif
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_SetBoolPref(pref, aValue, mIsDefault);
}
NS_IMETHODIMP nsPrefBranch::GetCharPref(const char *aPrefName, char **_retval)
{
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_CopyCharPref(pref, _retval, mIsDefault);
}
@ -190,12 +193,15 @@ NS_IMETHODIMP nsPrefBranch::SetCharPref(const char *aPrefName, const char *aValu
}
#endif
NS_ENSURE_ARG(aPrefName);
NS_ENSURE_ARG(aValue);
const char *pref = getPrefName(aPrefName);
return PREF_SetCharPref(pref, aValue, mIsDefault);
}
NS_IMETHODIMP nsPrefBranch::GetIntPref(const char *aPrefName, PRInt32 *_retval)
{
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_GetIntPref(pref, _retval, mIsDefault);
}
@ -209,12 +215,15 @@ NS_IMETHODIMP nsPrefBranch::SetIntPref(const char *aPrefName, PRInt32 aValue)
}
#endif
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_SetIntPref(pref, aValue, mIsDefault);
}
NS_IMETHODIMP nsPrefBranch::GetComplexValue(const char *aPrefName, const nsIID & aType, void **_retval)
{
NS_ENSURE_ARG(aPrefName);
nsresult rv;
nsXPIDLCString utf8String;
@ -381,6 +390,8 @@ NS_IMETHODIMP nsPrefBranch::SetComplexValue(const char *aPrefName, const nsIID &
}
#endif
NS_ENSURE_ARG(aPrefName);
nsresult rv = NS_NOINTERFACE;
if (aType.Equals(NS_GET_IID(nsILocalFile))) {
@ -470,6 +481,7 @@ NS_IMETHODIMP nsPrefBranch::ClearUserPref(const char *aPrefName)
}
#endif
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_ClearUserPref(pref);
}
@ -477,7 +489,7 @@ NS_IMETHODIMP nsPrefBranch::ClearUserPref(const char *aPrefName)
NS_IMETHODIMP nsPrefBranch::PrefHasUserValue(const char *aPrefName, PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
*_retval = PREF_HasUserPref(pref);
return NS_OK;
@ -492,6 +504,7 @@ NS_IMETHODIMP nsPrefBranch::LockPref(const char *aPrefName)
}
#endif
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_LockPref(pref, PR_TRUE);
}
@ -506,6 +519,7 @@ NS_IMETHODIMP nsPrefBranch::PrefIsLocked(const char *aPrefName, PRBool *_retval)
#endif
NS_ENSURE_ARG_POINTER(_retval);
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
*_retval = PREF_PrefIsLocked(pref);
return NS_OK;
@ -520,6 +534,7 @@ NS_IMETHODIMP nsPrefBranch::UnlockPref(const char *aPrefName)
}
#endif
NS_ENSURE_ARG(aPrefName);
const char *pref = getPrefName(aPrefName);
return PREF_LockPref(pref, PR_FALSE);
}
@ -539,6 +554,7 @@ NS_IMETHODIMP nsPrefBranch::DeleteBranch(const char *aStartingAt)
}
#endif
NS_ENSURE_ARG(aStartingAt);
const char *pref = getPrefName(aStartingAt);
return PREF_DeleteBranch(pref);
}
@ -551,7 +567,7 @@ NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, PRUint32 *aCou
EnumerateData ed;
nsAutoTArray<nsCString, 32> prefArray;
NS_ENSURE_ARG_POINTER(aStartingAt);
NS_ENSURE_ARG(aStartingAt);
NS_ENSURE_ARG_POINTER(aCount);
NS_ENSURE_ARG_POINTER(aChildArray);
@ -607,8 +623,8 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObser
PrefCallback *pCallback;
const char *pref;
NS_ENSURE_ARG_POINTER(aDomain);
NS_ENSURE_ARG_POINTER(aObserver);
NS_ENSURE_ARG(aDomain);
NS_ENSURE_ARG(aObserver);
// hold a weak reference to the observer if so requested
if (aHoldWeak) {
@ -641,7 +657,7 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObser
// We must pass a fully qualified preference name to the callback
// aDomain == nsnull is the only possible failure, and we trapped it with
// NS_ENSURE_ARG_POINTER above.
// NS_ENSURE_ARG above.
pref = getPrefName(aDomain);
PREF_RegisterCallback(pref, NotifyObserver, pCallback);
return NS_OK;
@ -649,8 +665,8 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObser
NS_IMETHODIMP nsPrefBranch::RemoveObserver(const char *aDomain, nsIObserver *aObserver)
{
NS_ENSURE_ARG_POINTER(aDomain);
NS_ENSURE_ARG_POINTER(aObserver);
NS_ENSURE_ARG(aDomain);
NS_ENSURE_ARG(aObserver);
nsresult rv = NS_OK;
@ -778,17 +794,15 @@ nsresult nsPrefBranch::GetDefaultFromPropertiesFile(const char *aPrefName, PRUni
const char *nsPrefBranch::getPrefName(const char *aPrefName)
{
NS_ASSERTION(aPrefName, "null pref name!");
// for speed, avoid strcpy if we can:
if (mPrefRoot.IsEmpty())
return aPrefName;
// isn't there a better way to do this? this is really kind of gross.
mPrefRoot.Truncate(mPrefRootLength);
// only append if anything to append
if ((nsnull != aPrefName) && (*aPrefName != '\0'))
mPrefRoot.Append(aPrefName);
mPrefRoot.Append(aPrefName);
return mPrefRoot.get();
}

View File

@ -60,6 +60,42 @@ function run_test() {
var pb = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
//**************************************************************************//
// Nullsafety
do_check_throws(function() {
pb.getPrefType(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getBoolPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setBoolPref(null, false); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getIntPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setIntPref(null, 0); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getCharPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setCharPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getComplexValue(null, Components.interfaces.nsISupportsString); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.setComplexValue(null, Components.interfaces.nsISupportsString, pb); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.clearUserPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.prefHasUserValue(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.lockPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.prefIsLocked(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.unlockPref(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.deleteBranch(null); }, Cr.NS_ERROR_INVALID_ARG);
do_check_throws(function() {
pb.getChildList(null); }, Cr.NS_ERROR_INVALID_ARG);
//**************************************************************************//
// Nonexisting user preferences