mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-05 00:02:37 +00:00
Bug 540566 nsCacheEntryDescriptor::GetDeviceID may crash in NS_strdup [@strlen | NS_strdup(char const*) ]
r=biesi
This commit is contained in:
parent
e1a2ff10c4
commit
0858f466c1
14
netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
14
netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
15
netwerk/test/unit/test_bug540566.js
Normal file
15
netwerk/test/unit/test_bug540566.js
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user