Skip to content

Commit 9600160

Browse files
committed
Bug 1626570 - Improve handling of copying arrays in netwerk/base/. r=valentin,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D72346
1 parent b4e558a commit 9600160

File tree

8 files changed

+47
-23
lines changed

8 files changed

+47
-23
lines changed

netwerk/base/BackgroundFileSaver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "BackgroundFileSaver.h"
88

99
#include "ScopedNSSTypes.h"
10+
#include "mozilla/ArrayAlgorithm.h"
1011
#include "mozilla/Casting.h"
1112
#include "mozilla/Logging.h"
1213
#include "mozilla/Telemetry.h"
@@ -257,7 +258,8 @@ BackgroundFileSaver::GetSignatureInfo(
257258
return NS_ERROR_NOT_AVAILABLE;
258259
}
259260
for (const auto& signatureChain : mSignatureInfo) {
260-
aSignatureInfo.AppendElement(signatureChain);
261+
aSignatureInfo.AppendElement(TransformIntoNewArray(
262+
signatureChain, [](const auto& element) { return element.Clone(); }));
261263
}
262264
return NS_OK;
263265
}
@@ -825,7 +827,7 @@ nsresult BackgroundFileSaver::ExtractSignatureInfo(const nsAString& filePath) {
825827
nsTArray<uint8_t> cert;
826828
cert.AppendElements(certChainElement->pCertContext->pbCertEncoded,
827829
certChainElement->pCertContext->cbCertEncoded);
828-
certList.AppendElement(cert);
830+
certList.AppendElement(std::move(cert));
829831
}
830832
if (extractionSuccess) {
831833
mSignatureInfo.AppendElement(std::move(certList));

netwerk/base/DashboardTypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ struct HttpConnInfo {
4444

4545
struct HttpRetParams {
4646
nsCString host;
47-
nsTArray<HttpConnInfo> active;
48-
nsTArray<HttpConnInfo> idle;
49-
nsTArray<HalfOpenSockets> halfOpens;
47+
CopyableTArray<HttpConnInfo> active;
48+
CopyableTArray<HttpConnInfo> idle;
49+
CopyableTArray<HalfOpenSockets> halfOpens;
5050
uint32_t counter;
5151
uint16_t port;
5252
nsCString httpVersion;

netwerk/base/LoadInfo.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ LoadInfo::LoadInfo(
235235
}
236236

237237
mInnerWindowID = aLoadingContext->OwnerDoc()->InnerWindowID();
238-
mAncestorPrincipals = aLoadingContext->OwnerDoc()->AncestorPrincipals();
238+
mAncestorPrincipals =
239+
aLoadingContext->OwnerDoc()->AncestorPrincipals().Clone();
239240
mAncestorOuterWindowIDs =
240-
aLoadingContext->OwnerDoc()->AncestorOuterWindowIDs();
241+
aLoadingContext->OwnerDoc()->AncestorOuterWindowIDs().Clone();
241242
MOZ_DIAGNOSTIC_ASSERT(mAncestorPrincipals.Length() ==
242243
mAncestorOuterWindowIDs.Length());
243244
mDocumentHasUserInteracted =
@@ -596,8 +597,8 @@ LoadInfo::LoadInfo(dom::CanonicalBrowsingContext* aBrowsingContext,
596597
ancestorOuterWindowIDs.AppendElement(ancestorWGP->OuterWindowId());
597598
ancestorBC = ancestorWGP->BrowsingContext();
598599
}
599-
mAncestorPrincipals = ancestorPrincipals;
600-
mAncestorOuterWindowIDs = ancestorOuterWindowIDs;
600+
mAncestorPrincipals = std::move(ancestorPrincipals);
601+
mAncestorOuterWindowIDs = std::move(ancestorOuterWindowIDs);
601602
MOZ_DIAGNOSTIC_ASSERT(mAncestorPrincipals.Length() ==
602603
mAncestorOuterWindowIDs.Length());
603604

@@ -759,11 +760,11 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
759760
mSendCSPViolationEvents(rhs.mSendCSPViolationEvents),
760761
mOriginAttributes(rhs.mOriginAttributes),
761762
mRedirectChainIncludingInternalRedirects(
762-
rhs.mRedirectChainIncludingInternalRedirects),
763-
mRedirectChain(rhs.mRedirectChain),
764-
mAncestorPrincipals(rhs.mAncestorPrincipals),
765-
mAncestorOuterWindowIDs(rhs.mAncestorOuterWindowIDs),
766-
mCorsUnsafeHeaders(rhs.mCorsUnsafeHeaders),
763+
rhs.mRedirectChainIncludingInternalRedirects.Clone()),
764+
mRedirectChain(rhs.mRedirectChain.Clone()),
765+
mAncestorPrincipals(rhs.mAncestorPrincipals.Clone()),
766+
mAncestorOuterWindowIDs(rhs.mAncestorOuterWindowIDs.Clone()),
767+
mCorsUnsafeHeaders(rhs.mCorsUnsafeHeaders.Clone()),
767768
mRequestBlockingReason(rhs.mRequestBlockingReason),
768769
mForcePreflight(rhs.mForcePreflight),
769770
mIsPreflight(rhs.mIsPreflight),
@@ -865,8 +866,8 @@ LoadInfo::LoadInfo(
865866
mSendCSPViolationEvents(aSendCSPViolationEvents),
866867
mOriginAttributes(aOriginAttributes),
867868
mAncestorPrincipals(std::move(aAncestorPrincipals)),
868-
mAncestorOuterWindowIDs(aAncestorOuterWindowIDs),
869-
mCorsUnsafeHeaders(aCorsUnsafeHeaders),
869+
mAncestorOuterWindowIDs(aAncestorOuterWindowIDs.Clone()),
870+
mCorsUnsafeHeaders(aCorsUnsafeHeaders.Clone()),
870871
mRequestBlockingReason(aRequestBlockingReason),
871872
mForcePreflight(aForcePreflight),
872873
mIsPreflight(aIsPreflight),
@@ -1561,7 +1562,7 @@ void LoadInfo::SetCorsPreflightInfo(const nsTArray<nsCString>& aHeaders,
15611562
bool aForcePreflight) {
15621563
MOZ_ASSERT(GetSecurityMode() == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS);
15631564
MOZ_ASSERT(!mInitialSecurityCheckDone);
1564-
mCorsUnsafeHeaders = aHeaders;
1565+
mCorsUnsafeHeaders = aHeaders.Clone();
15651566
mForcePreflight = aForcePreflight;
15661567
}
15671568

netwerk/base/PartiallySeekableInputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PartiallySeekableInputStream::PartiallySeekableInputStream(
5858
mWeakAsyncInputStream(nullptr),
5959
mWeakInputStreamLength(nullptr),
6060
mWeakAsyncInputStreamLength(nullptr),
61-
mCachedBuffer(aClonedFrom->mCachedBuffer),
61+
mCachedBuffer(aClonedFrom->mCachedBuffer.Clone()),
6262
mBufferSize(aClonedFrom->mBufferSize),
6363
mPos(aClonedFrom->mPos),
6464
mClosed(aClonedFrom->mClosed),

netwerk/base/SSLTokensCache.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
#include "SSLTokensCache.h"
6+
#include "mozilla/ArrayAlgorithm.h"
67
#include "mozilla/Preferences.h"
78
#include "mozilla/Logging.h"
89
#include "nsIOService.h"
@@ -36,6 +37,20 @@ class ExpirationComparator {
3637
}
3738
};
3839

40+
SessionCacheInfo SessionCacheInfo::Clone() const {
41+
SessionCacheInfo result;
42+
result.mEVStatus = mEVStatus;
43+
result.mCertificateTransparencyStatus = mCertificateTransparencyStatus;
44+
result.mServerCertBytes = mServerCertBytes.Clone();
45+
result.mSucceededCertChainBytes =
46+
mSucceededCertChainBytes
47+
? Some(TransformIntoNewArray(
48+
*mSucceededCertChainBytes,
49+
[](const auto& element) { return element.Clone(); }))
50+
: Nothing();
51+
return result;
52+
}
53+
3954
StaticRefPtr<SSLTokensCache> SSLTokensCache::gInstance;
4055
StaticMutex SSLTokensCache::sLock;
4156

@@ -206,7 +221,11 @@ nsresult SSLTokensCache::Put(const nsACString& aKey, const uint8_t* aToken,
206221
rec->mSessionCacheInfo.mServerCertBytes = std::move(certBytes);
207222

208223
rec->mSessionCacheInfo.mSucceededCertChainBytes =
209-
std::move(succeededCertChainBytes);
224+
succeededCertChainBytes
225+
? Some(TransformIntoNewArray(
226+
*succeededCertChainBytes,
227+
[](auto& element) { return nsTArray(std::move(element)); }))
228+
: Nothing();
210229

211230
if (isEV) {
212231
rec->mSessionCacheInfo.mEVStatus = psm::EVStatus::EV;
@@ -243,7 +262,7 @@ nsresult SSLTokensCache::Get(const nsACString& aKey,
243262

244263
if (gInstance->mTokenCacheRecords.Get(aKey, &rec)) {
245264
if (rec->mToken.Length()) {
246-
aToken = rec->mToken;
265+
aToken = rec->mToken.Clone();
247266
return NS_OK;
248267
}
249268
}
@@ -268,7 +287,7 @@ bool SSLTokensCache::GetSessionCacheInfo(const nsACString& aKey,
268287
TokenCacheRecord* rec = nullptr;
269288

270289
if (gInstance->mTokenCacheRecords.Get(aKey, &rec)) {
271-
aResult = rec->mSessionCacheInfo;
290+
aResult = rec->mSessionCacheInfo.Clone();
272291
return true;
273292
}
274293

netwerk/base/SSLTokensCache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace mozilla {
1818
namespace net {
1919

2020
struct SessionCacheInfo {
21+
SessionCacheInfo Clone() const;
22+
2123
psm::EVStatus mEVStatus = psm::EVStatus::NotEV;
2224
uint16_t mCertificateTransparencyStatus =
2325
nsITransportSecurityInfo::CERTIFICATE_TRANSPARENCY_NOT_APPLICABLE;

netwerk/base/nsMIMEInputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ bool nsMIMEInputStream::Deserialize(
392392
const MIMEInputStreamParams& params = aParams.get_MIMEInputStreamParams();
393393
const Maybe<InputStreamParams>& wrappedParams = params.optionalStream();
394394

395-
mHeaders = params.headers();
395+
mHeaders = params.headers().Clone();
396396
mStartedReading = params.startedReading();
397397

398398
if (wrappedParams.isSome()) {

netwerk/base/nsSocketTransportService2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class nsSocketTransportService final : public nsPISocketTransportService,
291291
// <1> the less-or-equal port number of the range to remap
292292
// <2> the port number to remap to, when the given port number falls to the
293293
// range
294-
typedef nsTArray<Tuple<uint16_t, uint16_t, uint16_t>> TPortRemapping;
294+
typedef CopyableTArray<Tuple<uint16_t, uint16_t, uint16_t>> TPortRemapping;
295295
Maybe<TPortRemapping> mPortRemapping;
296296

297297
// Called on the socket thread to apply the mapping build on the main thread

0 commit comments

Comments
 (0)