Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nspr.h" |
michael@0 | 7 | #include "nscore.h" |
michael@0 | 8 | #include "nsCOMPtr.h" |
michael@0 | 9 | #include "nsIIOService.h" |
michael@0 | 10 | #include "nsIServiceManager.h" |
michael@0 | 11 | #include "nsIComponentRegistrar.h" |
michael@0 | 12 | #include "nsIURI.h" |
michael@0 | 13 | |
michael@0 | 14 | static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); |
michael@0 | 15 | |
michael@0 | 16 | nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { |
michael@0 | 17 | nsresult rv; |
michael@0 | 18 | nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv)); |
michael@0 | 19 | if (NS_FAILED(rv)) return rv; |
michael@0 | 20 | |
michael@0 | 21 | return serv->MakeAbsolute(relativeInfo, baseURI, _retval); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | nsresult URLMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { |
michael@0 | 25 | return baseURI->MakeAbsolute(relativeInfo, _retval); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | int |
michael@0 | 29 | main(int argc, char* argv[]) |
michael@0 | 30 | { |
michael@0 | 31 | nsresult rv = NS_OK; |
michael@0 | 32 | if (argc < 4) { |
michael@0 | 33 | printf("usage: %s int (loop count) baseURL relativeSpec\n", argv[0]); |
michael@0 | 34 | return -1; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | uint32_t cycles = atoi(argv[1]); |
michael@0 | 38 | char *base = argv[2]; |
michael@0 | 39 | char *rel = argv[3]; |
michael@0 | 40 | { |
michael@0 | 41 | nsCOMPtr<nsIServiceManager> servMan; |
michael@0 | 42 | NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); |
michael@0 | 43 | nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); |
michael@0 | 44 | NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); |
michael@0 | 45 | if (registrar) |
michael@0 | 46 | registrar->AutoRegister(nullptr); |
michael@0 | 47 | |
michael@0 | 48 | nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv)); |
michael@0 | 49 | if (NS_FAILED(rv)) return rv; |
michael@0 | 50 | |
michael@0 | 51 | nsCOMPtr<nsIURI> uri; |
michael@0 | 52 | rv = serv->NewURI(base, nullptr, getter_AddRefs(uri)); |
michael@0 | 53 | if (NS_FAILED(rv)) return rv; |
michael@0 | 54 | |
michael@0 | 55 | char *absURLString; |
michael@0 | 56 | uint32_t i = 0; |
michael@0 | 57 | while (i++ < cycles) { |
michael@0 | 58 | rv = ServiceMakeAbsolute(uri, rel, &absURLString); |
michael@0 | 59 | if (NS_FAILED(rv)) return rv; |
michael@0 | 60 | nsMemory::Free(absURLString); |
michael@0 | 61 | |
michael@0 | 62 | rv = URLMakeAbsolute(uri, rel, &absURLString); |
michael@0 | 63 | nsMemory::Free(absURLString); |
michael@0 | 64 | } |
michael@0 | 65 | } // this scopes the nsCOMPtrs |
michael@0 | 66 | // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM |
michael@0 | 67 | NS_ShutdownXPCOM(nullptr); |
michael@0 | 68 | return rv; |
michael@0 | 69 | } |