Bug 540566 nsCacheEntryDescriptor::GetDeviceID may crash in NS_strdup [@strlen | NS_strdup(char const*) ]

r=biesi
This commit is contained in:
timeless@mozdev.org 2010-02-21 15:53:13 +01:00
parent e1a2ff10c4
commit 0858f466c1
2 changed files with 25 additions and 4 deletions

View File

@ -89,14 +89,20 @@ nsCacheEntryDescriptor::GetClientID(char ** result)
NS_IMETHODIMP
nsCacheEntryDescriptor::GetDeviceID(char ** result)
nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID)
{
NS_ENSURE_ARG_POINTER(result);
NS_ENSURE_ARG_POINTER(aDeviceID);
nsCacheServiceAutoLock lock;
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
*result = NS_strdup(mCacheEntry->GetDeviceID());
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
const char* deviceID = mCacheEntry->GetDeviceID();
if (!deviceID) {
*aDeviceID = nsnull;
return NS_OK;
}
*aDeviceID = NS_strdup(deviceID);
return *aDeviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -0,0 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function run_test() {
var cs = Components.classes["@mozilla.org/network/cache-service;1"].
getService(Components.interfaces.nsICacheService);
var nsICache = Components.interfaces.nsICache;
var session = cs.createSession("client",
nsICache.STORE_ANYWHERE,
true);
var entry = session.openCacheEntry("key", nsICache.STORE_ON_DISK, true);
entry.deviceID;
// if the above line does not crash, the test was successful
}