From 4b90811978c29d8dae05c8b4bc76d8616e8d73c4 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 19 Sep 2018 15:45:27 +0200 Subject: Add a null check in nsHttpTransaction::Close. This resolves #776. --- netwerk/protocol/http/nsHttpTransaction.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'netwerk') diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp index 8d837d172..76e0a4ad9 100644 --- a/netwerk/protocol/http/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/nsHttpTransaction.cpp @@ -1164,7 +1164,9 @@ nsHttpTransaction::Close(nsresult reason) } // closing this pipe triggers the channel's OnStopRequest method. - mPipeOut->CloseWithStatus(reason); + if (mPipeOut) { + mPipeOut->CloseWithStatus(reason); + } #ifdef WIN32 // bug 1153929 MOZ_DIAGNOSTIC_ASSERT(mPipeOut); -- cgit v1.2.3 From 5715a00c8c4fa22055e57f6f30b1fef203ae6972 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 25 Sep 2018 22:53:09 -0400 Subject: backport mozbug 1344613 - Avoid possibility of null pointer crash in nsSOCKSIOLayer.cpp r=mayhemer --- netwerk/socket/nsSOCKSIOLayer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'netwerk') diff --git a/netwerk/socket/nsSOCKSIOLayer.cpp b/netwerk/socket/nsSOCKSIOLayer.cpp index 22f5751fb..5429637c1 100644 --- a/netwerk/socket/nsSOCKSIOLayer.cpp +++ b/netwerk/socket/nsSOCKSIOLayer.cpp @@ -229,6 +229,7 @@ nsSOCKSSocketInfo::nsSOCKSSocketInfo() , mDataLength(0) , mReadOffset(0) , mAmountToRead(0) + , mFD(nullptr) , mVersion(-1) , mDestinationFamily(AF_INET) , mFlags(0) -- cgit v1.2.3 From c5c9445e3adf6b65c98f6810551d7c3d64133134 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 25 Sep 2018 23:03:28 -0400 Subject: backport mozbug 1334776 - CVE-2017-7797 Header name interning leaks across origins Potential attack: session supercookie. [Moz Notes](https://bugzilla.mozilla.org/show_bug.cgi?id=1334776#c5): "The problem is that for unknown header names we store the first one we see and then later we case-insensitively match against that name *globally*. That means you can track if a user agent has already seen a certain header name used (by using a different casing and observing whether it gets normalized). This would allow you to see if a user has used a sensitive service that uses custom header names, or allows you to track a user across sites, by teaching the browser about a certain header case once and then observing if different casings get normalized to that. What we should do instead is only store the casing for a header name for each header list and not globally. That way it only leaks where it's expected (and necessary) to leak." [Moz fix note](https://bugzilla.mozilla.org/show_bug.cgi?id=1334776#c8): "nsHttpAtom now holds the old nsHttpAtom and a string that is case sensitive (only for not standard headers). So nsHttpAtom holds a pointer to a header name. (header names are store on a static structure). This is how it used to be. I left that part the same but added a nsCString which holds a string that was used to resoled the header name. So when we parse headers we call ResolveHeader with a char*. If it is a new header name the char* will be stored in a HttpHeapAtom, nsHttpAtom::_val will point to HttpHeapAtom::value and the same strings will be stored in mLocalCaseSensitiveHeader. For the first resolve request they will be the same but for the following maybe not. At the end this nsHttpAtom will be stored in nsHttpHeaderArray. For all operation we will used the old char* except when we are returning it to a script using VisitHeaders." --- netwerk/protocol/http/HttpBaseChannel.cpp | 18 +--- netwerk/protocol/http/PHttpChannelParams.h | 15 +++- netwerk/protocol/http/nsHttpHeaderArray.cpp | 99 ++++++++++++++++++---- netwerk/protocol/http/nsHttpHeaderArray.h | 36 ++++++-- netwerk/protocol/http/nsHttpRequestHead.cpp | 23 ++++- netwerk/protocol/http/nsHttpRequestHead.h | 4 +- netwerk/protocol/http/nsHttpResponseHead.cpp | 50 ++++++++--- netwerk/protocol/http/nsHttpResponseHead.h | 6 +- netwerk/test/unit/test_bug1064258.js | 2 +- .../test/unit/test_original_sent_received_head.js | 18 ++-- 10 files changed, 204 insertions(+), 67 deletions(-) (limited to 'netwerk') diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index c4e764d26..03123ceb0 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -1665,13 +1665,7 @@ HttpBaseChannel::SetRequestHeader(const nsACString& aHeader, return NS_ERROR_INVALID_ARG; } - nsHttpAtom atom = nsHttp::ResolveAtom(flatHeader.get()); - if (!atom) { - NS_WARNING("failed to resolve atom"); - return NS_ERROR_NOT_AVAILABLE; - } - - return mRequestHead.SetHeader(atom, flatValue, aMerge); + return mRequestHead.SetHeader(aHeader, flatValue, aMerge); } NS_IMETHODIMP @@ -1688,13 +1682,7 @@ HttpBaseChannel::SetEmptyRequestHeader(const nsACString& aHeader) return NS_ERROR_INVALID_ARG; } - nsHttpAtom atom = nsHttp::ResolveAtom(flatHeader.get()); - if (!atom) { - NS_WARNING("failed to resolve atom"); - return NS_ERROR_NOT_AVAILABLE; - } - - return mRequestHead.SetEmptyHeader(atom); + return mRequestHead.SetEmptyHeader(aHeader); } NS_IMETHODIMP @@ -1750,7 +1738,7 @@ HttpBaseChannel::SetResponseHeader(const nsACString& header, mResponseHeadersModified = true; - return mResponseHead->SetHeader(atom, value, merge); + return mResponseHead->SetHeader(header, value, merge); } NS_IMETHODIMP diff --git a/netwerk/protocol/http/PHttpChannelParams.h b/netwerk/protocol/http/PHttpChannelParams.h index 4df5c7832..b04f57306 100644 --- a/netwerk/protocol/http/PHttpChannelParams.h +++ b/netwerk/protocol/http/PHttpChannelParams.h @@ -98,7 +98,11 @@ struct ParamTraits static void Write(Message* aMsg, const paramType& aParam) { - WriteParam(aMsg, aParam.header); + if (aParam.headerNameOriginal.IsEmpty()) { + WriteParam(aMsg, aParam.header); + } else { + WriteParam(aMsg, aParam.headerNameOriginal); + } WriteParam(aMsg, aParam.value); switch (aParam.variety) { case mozilla::net::nsHttpHeaderArray::eVarietyUnknown: @@ -124,11 +128,18 @@ struct ParamTraits static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { uint8_t variety; - if (!ReadParam(aMsg, aIter, &aResult->header) || + nsAutoCString header; + if (!ReadParam(aMsg, aIter, &header) || !ReadParam(aMsg, aIter, &aResult->value) || !ReadParam(aMsg, aIter, &variety)) return false; + mozilla::net::nsHttpAtom atom = mozilla::net::nsHttp::ResolveAtom(header); + aResult->header = atom; + if (!header.Equals(atom.get())) { + aResult->headerNameOriginal = header; + } + switch (variety) { case 0: aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyUnknown; diff --git a/netwerk/protocol/http/nsHttpHeaderArray.cpp b/netwerk/protocol/http/nsHttpHeaderArray.cpp index 670300dea..1030bc91e 100644 --- a/netwerk/protocol/http/nsHttpHeaderArray.cpp +++ b/netwerk/protocol/http/nsHttpHeaderArray.cpp @@ -18,11 +18,36 @@ namespace net { //----------------------------------------------------------------------------- // nsHttpHeaderArray //----------------------------------------------------------------------------- + +nsresult +nsHttpHeaderArray::SetHeader(const nsACString &headerName, + const nsACString &value, + bool merge, + nsHttpHeaderArray::HeaderVariety variety) +{ + nsHttpAtom header = nsHttp::ResolveAtom(PromiseFlatCString(headerName).get()); + if (!header) { + NS_WARNING("failed to resolve atom"); + return NS_ERROR_NOT_AVAILABLE; + } + return SetHeader(header, headerName, value, merge, variety); +} + nsresult nsHttpHeaderArray::SetHeader(nsHttpAtom header, const nsACString &value, bool merge, nsHttpHeaderArray::HeaderVariety variety) +{ + return SetHeader(header, EmptyCString(), value, merge, variety); +} + +nsresult +nsHttpHeaderArray::SetHeader(nsHttpAtom header, + const nsACString &headerName, + const nsACString &value, + bool merge, + nsHttpHeaderArray::HeaderVariety variety) { MOZ_ASSERT((variety == eVarietyResponse) || (variety == eVarietyRequestDefault) || @@ -51,7 +76,7 @@ nsHttpHeaderArray::SetHeader(nsHttpAtom header, MOZ_ASSERT(!entry || variety != eVarietyRequestDefault, "Cannot set default entry which overrides existing entry!"); if (!entry) { - return SetHeader_internal(header, value, variety); + return SetHeader_internal(header, headerName, value, variety); } else if (merge && !IsSingletonHeader(header)) { return MergeHeader(header, entry, value, variety); } else { @@ -59,7 +84,7 @@ nsHttpHeaderArray::SetHeader(nsHttpAtom header, if (entry->variety == eVarietyResponseNetOriginalAndResponse) { MOZ_ASSERT(variety == eVarietyResponse); entry->variety = eVarietyResponseNetOriginal; - return SetHeader_internal(header, value, variety); + return SetHeader_internal(header, headerName, value, variety); } else { entry->value = value; entry->variety = variety; @@ -71,6 +96,7 @@ nsHttpHeaderArray::SetHeader(nsHttpAtom header, nsresult nsHttpHeaderArray::SetHeader_internal(nsHttpAtom header, + const nsACString &headerName, const nsACString &value, nsHttpHeaderArray::HeaderVariety variety) { @@ -79,14 +105,26 @@ nsHttpHeaderArray::SetHeader_internal(nsHttpAtom header, return NS_ERROR_OUT_OF_MEMORY; } entry->header = header; + // Only save original form of a header if it is different than the header + // atom string. + if (!headerName.Equals(header.get())) { + entry->headerNameOriginal = headerName; + } entry->value = value; entry->variety = variety; return NS_OK; } nsresult -nsHttpHeaderArray::SetEmptyHeader(nsHttpAtom header, HeaderVariety variety) +nsHttpHeaderArray::SetEmptyHeader(const nsACString &headerName, + HeaderVariety variety) { + nsHttpAtom header = nsHttp::ResolveAtom(PromiseFlatCString(headerName).get()); + if (!header) { + NS_WARNING("failed to resolve atom"); + return NS_ERROR_NOT_AVAILABLE; + } + MOZ_ASSERT((variety == eVarietyResponse) || (variety == eVarietyRequestDefault) || (variety == eVarietyRequestOverride), @@ -104,11 +142,12 @@ nsHttpHeaderArray::SetEmptyHeader(nsHttpAtom header, HeaderVariety variety) entry->variety = eVarietyResponseNetOriginal; } - return SetHeader_internal(header, EmptyCString(), variety); + return SetHeader_internal(header, headerName, EmptyCString(), variety); } nsresult nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, + const nsACString &headerNameOriginal, const nsACString &value, bool response) { @@ -125,7 +164,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, LOG(("Ignoring Empty Header: %s\n", header.get())); if (response) { // Set header as original but not as response header. - return SetHeader_internal(header, value, + return SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } return NS_OK; // ignore empty headers by default @@ -135,7 +174,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, if (response) { variety = eVarietyResponseNetOriginalAndResponse; } - return SetHeader_internal(header, value, variety); + return SetHeader_internal(header, headerNameOriginal, value, variety); } else if (!IsSingletonHeader(header)) { HeaderVariety variety = eVarietyRequestOverride; @@ -147,7 +186,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, return rv; } if (response) { - rv = SetHeader_internal(header, value, + rv = SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } return rv; @@ -164,7 +203,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, } if (response) { - return SetHeader_internal(header, value, + return SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } } @@ -174,6 +213,7 @@ nsHttpHeaderArray::SetHeaderFromNet(nsHttpAtom header, nsresult nsHttpHeaderArray::SetResponseHeaderFromCache(nsHttpAtom header, + const nsACString &headerNameOriginal, const nsACString &value, nsHttpHeaderArray::HeaderVariety variety) { @@ -183,7 +223,7 @@ nsHttpHeaderArray::SetResponseHeaderFromCache(nsHttpAtom header, "eVarietyResponseNetOriginal"); if (variety == eVarietyResponseNetOriginal) { - return SetHeader_internal(header, value, + return SetHeader_internal(header, headerNameOriginal, value, eVarietyResponseNetOriginal); } else { nsTArray::index_type index = 0; @@ -203,7 +243,8 @@ nsHttpHeaderArray::SetResponseHeaderFromCache(nsHttpAtom header, } } while (index != mHeaders.NoIndex); // If we are here, we have not found an entry so add a new one. - return SetHeader_internal(header, value, eVarietyResponse); + return SetHeader_internal(header, headerNameOriginal, value, + eVarietyResponse); } } @@ -260,8 +301,16 @@ nsHttpHeaderArray::GetOriginalHeader(nsHttpAtom aHeader, if (entry.variety == eVarietyResponse) { continue; } + + nsAutoCString hdr; + if (entry.headerNameOriginal.IsEmpty()) { + hdr = nsDependentCString(entry.header); + } else { + hdr = entry.headerNameOriginal; + } + rv = NS_OK; - if (NS_FAILED(aVisitor->VisitHeader(nsDependentCString(entry.header), + if (NS_FAILED(aVisitor->VisitHeader(hdr, entry.value))) { break; } @@ -298,8 +347,14 @@ nsHttpHeaderArray::VisitHeaders(nsIHttpHeaderVisitor *visitor, nsHttpHeaderArray } else if (filter == eFilterResponseOriginal && entry.variety == eVarietyResponse) { continue; } - rv = visitor->VisitHeader( - nsDependentCString(entry.header), entry.value); + + nsAutoCString hdr; + if (entry.headerNameOriginal.IsEmpty()) { + hdr = nsDependentCString(entry.header); + } else { + hdr = entry.headerNameOriginal; + } + rv = visitor->VisitHeader(hdr, entry.value); if NS_FAILED(rv) { return rv; } @@ -310,6 +365,7 @@ nsHttpHeaderArray::VisitHeaders(nsIHttpHeaderVisitor *visitor, nsHttpHeaderArray /*static*/ nsresult nsHttpHeaderArray::ParseHeaderLine(const nsACString& line, nsHttpAtom *hdr, + nsACString *headerName, nsACString *val) { // @@ -360,6 +416,7 @@ nsHttpHeaderArray::ParseHeaderLine(const nsACString& line, // assign return values if (hdr) *hdr = atom; if (val) val->Assign(p, p2 - p + 1); + if (headerName) headerName->Assign(sub); return NS_OK; } @@ -397,7 +454,11 @@ nsHttpHeaderArray::Flatten(nsACString &buf, bool pruneProxyHeaders, continue; } - buf.Append(entry.header); + if (entry.headerNameOriginal.IsEmpty()) { + buf.Append(entry.header); + } else { + buf.Append(entry.headerNameOriginal); + } buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); @@ -415,7 +476,11 @@ nsHttpHeaderArray::FlattenOriginalHeader(nsACString &buf) continue; } - buf.Append(entry.header); + if (entry.headerNameOriginal.IsEmpty()) { + buf.Append(entry.header); + } else { + buf.Append(entry.headerNameOriginal); + } buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); @@ -423,11 +488,13 @@ nsHttpHeaderArray::FlattenOriginalHeader(nsACString &buf) } const char * -nsHttpHeaderArray::PeekHeaderAt(uint32_t index, nsHttpAtom &header) const +nsHttpHeaderArray::PeekHeaderAt(uint32_t index, nsHttpAtom &header, + nsACString &headerNameOriginal) const { const nsEntry &entry = mHeaders[index]; header = entry.header; + headerNameOriginal = entry.headerNameOriginal; return entry.value.get(); } diff --git a/netwerk/protocol/http/nsHttpHeaderArray.h b/netwerk/protocol/http/nsHttpHeaderArray.h index 91b91f04a..3ffdfa814 100644 --- a/netwerk/protocol/http/nsHttpHeaderArray.h +++ b/netwerk/protocol/http/nsHttpHeaderArray.h @@ -49,19 +49,30 @@ public: }; // Used by internal setters: to set header from network use SetHeaderFromNet + nsresult SetHeader(const nsACString &headerName, + const nsACString &value, + bool merge, HeaderVariety variety); nsresult SetHeader(nsHttpAtom header, const nsACString &value, bool merge, HeaderVariety variety); + nsresult SetHeader(nsHttpAtom header, + const nsACString &headerName, + const nsACString &value, + bool merge, HeaderVariety variety); // Used by internal setters to set an empty header - nsresult SetEmptyHeader(nsHttpAtom header, HeaderVariety variety); + nsresult SetEmptyHeader(const nsACString &headerName, HeaderVariety variety); // Merges supported headers. For other duplicate values, determines if error // needs to be thrown or 1st value kept. // For the response header we keep the original headers as well. - nsresult SetHeaderFromNet(nsHttpAtom header, const nsACString &value, + nsresult SetHeaderFromNet(nsHttpAtom header, + const nsACString &headerNameOriginal, + const nsACString &value, bool response); - nsresult SetResponseHeaderFromCache(nsHttpAtom header, const nsACString &value, + nsresult SetResponseHeaderFromCache(nsHttpAtom header, + const nsACString &headerNameOriginal, + const nsACString &value, HeaderVariety variety); nsresult GetHeader(nsHttpAtom header, nsACString &value) const; @@ -97,15 +108,17 @@ public: // parse a header line, return the header atom and a pointer to the // header value (the substring of the header line -- do not free). static nsresult ParseHeaderLine(const nsACString& line, - nsHttpAtom *header=nullptr, - nsACString* value=nullptr); + nsHttpAtom *header = nullptr, + nsACString *headerNameOriginal = nullptr, + nsACString *value = nullptr); void Flatten(nsACString &, bool pruneProxyHeaders, bool pruneTransients); void FlattenOriginalHeader(nsACString &); uint32_t Count() const { return mHeaders.Length(); } - const char *PeekHeaderAt(uint32_t i, nsHttpAtom &header) const; + const char *PeekHeaderAt(uint32_t i, nsHttpAtom &header, + nsACString &headerNameOriginal) const; void Clear(); @@ -113,6 +126,7 @@ public: struct nsEntry { nsHttpAtom header; + nsCString headerNameOriginal; nsCString value; HeaderVariety variety = eVarietyUnknown; @@ -140,7 +154,9 @@ private: int32_t LookupEntry(nsHttpAtom header, nsEntry **); nsresult MergeHeader(nsHttpAtom header, nsEntry *entry, const nsACString &value, HeaderVariety variety); - nsresult SetHeader_internal(nsHttpAtom header, const nsACString &value, + nsresult SetHeader_internal(nsHttpAtom header, + const nsACString &headerName, + const nsACString &value, HeaderVariety variety); // Header cannot be merged: only one value possible @@ -257,7 +273,11 @@ nsHttpHeaderArray::MergeHeader(nsHttpAtom header, if (entry->variety == eVarietyResponseNetOriginalAndResponse) { MOZ_ASSERT(variety == eVarietyResponse); entry->variety = eVarietyResponseNetOriginal; - nsresult rv = SetHeader_internal(header, newValue, eVarietyResponse); + // Copy entry->headerNameOriginal because in SetHeader_internal we are going + // to a new one and a realocation can happen. + nsCString headerNameOriginal = entry->headerNameOriginal; + nsresult rv = SetHeader_internal(header, headerNameOriginal, + newValue, eVarietyResponse); if (NS_FAILED(rv)) { return rv; } diff --git a/netwerk/protocol/http/nsHttpRequestHead.cpp b/netwerk/protocol/http/nsHttpRequestHead.cpp index 094a79457..b366a8d54 100644 --- a/netwerk/protocol/http/nsHttpRequestHead.cpp +++ b/netwerk/protocol/http/nsHttpRequestHead.cpp @@ -130,6 +130,20 @@ nsHttpRequestHead::Origin(nsACString &aOrigin) aOrigin = mOrigin; } +nsresult +nsHttpRequestHead::SetHeader(const nsACString &h, const nsACString &v, + bool m /*= false*/) +{ + ReentrantMonitorAutoEnter mon(mReentrantMonitor); + + if (mInVisitHeaders) { + return NS_ERROR_FAILURE; + } + + return mHeaders.SetHeader(h, v, m, + nsHttpHeaderArray::eVarietyRequestOverride); +} + nsresult nsHttpRequestHead::SetHeader(nsHttpAtom h, const nsACString &v, bool m /*= false*/) @@ -158,7 +172,7 @@ nsHttpRequestHead::SetHeader(nsHttpAtom h, const nsACString &v, bool m, } nsresult -nsHttpRequestHead::SetEmptyHeader(nsHttpAtom h) +nsHttpRequestHead::SetEmptyHeader(const nsACString &h) { ReentrantMonitorAutoEnter mon(mReentrantMonitor); @@ -253,6 +267,7 @@ nsHttpRequestHead::ParseHeaderSet(const char *buffer) { ReentrantMonitorAutoEnter mon(mReentrantMonitor); nsHttpAtom hdr; + nsAutoCString headerNameOriginal; nsAutoCString val; while (buffer) { const char *eof = strchr(buffer, '\r'); @@ -262,9 +277,13 @@ nsHttpRequestHead::ParseHeaderSet(const char *buffer) if (NS_SUCCEEDED(nsHttpHeaderArray::ParseHeaderLine( nsDependentCSubstring(buffer, eof - buffer), &hdr, + &headerNameOriginal, &val))) { - mHeaders.SetHeaderFromNet(hdr, val, false); + mHeaders.SetHeaderFromNet(hdr, + headerNameOriginal, + val, + false); } buffer = eof + 1; if (*buffer == '\n') { diff --git a/netwerk/protocol/http/nsHttpRequestHead.h b/netwerk/protocol/http/nsHttpRequestHead.h index 415968083..b7020d33a 100644 --- a/netwerk/protocol/http/nsHttpRequestHead.h +++ b/netwerk/protocol/http/nsHttpRequestHead.h @@ -57,10 +57,12 @@ public: int32_t port); void Origin(nsACString &aOrigin); + nsresult SetHeader(const nsACString &h, const nsACString &v, + bool m=false); nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false); nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m, nsHttpHeaderArray::HeaderVariety variety); - nsresult SetEmptyHeader(nsHttpAtom h); + nsresult SetEmptyHeader(const nsACString &h); nsresult GetHeader(nsHttpAtom h, nsACString &v); nsresult ClearHeader(nsHttpAtom h); diff --git a/netwerk/protocol/http/nsHttpResponseHead.cpp b/netwerk/protocol/http/nsHttpResponseHead.cpp index 6d384c488..fa6430b82 100644 --- a/netwerk/protocol/http/nsHttpResponseHead.cpp +++ b/netwerk/protocol/http/nsHttpResponseHead.cpp @@ -136,6 +136,26 @@ nsHttpResponseHead::Immutable() return mCacheControlImmutable; } +nsresult +nsHttpResponseHead::SetHeader(const nsACString &hdr, + const nsACString &val, + bool merge) +{ + ReentrantMonitorAutoEnter monitor(mReentrantMonitor); + + if (mInVisitHeaders) { + return NS_ERROR_FAILURE; + } + + nsHttpAtom atom = nsHttp::ResolveAtom(PromiseFlatCString(hdr).get()); + if (!atom) { + NS_WARNING("failed to resolve atom"); + return NS_ERROR_NOT_AVAILABLE; + } + + return SetHeader_locked(atom, hdr, val, merge); +} + nsresult nsHttpResponseHead::SetHeader(nsHttpAtom hdr, const nsACString &val, @@ -147,24 +167,25 @@ nsHttpResponseHead::SetHeader(nsHttpAtom hdr, return NS_ERROR_FAILURE; } - return SetHeader_locked(hdr, val, merge); + return SetHeader_locked(hdr, EmptyCString(), val, merge); } nsresult -nsHttpResponseHead::SetHeader_locked(nsHttpAtom hdr, +nsHttpResponseHead::SetHeader_locked(nsHttpAtom atom, + const nsACString &hdr, const nsACString &val, bool merge) { - nsresult rv = mHeaders.SetHeader(hdr, val, merge, + nsresult rv = mHeaders.SetHeader(atom, hdr, val, merge, nsHttpHeaderArray::eVarietyResponse); if (NS_FAILED(rv)) return rv; // respond to changes in these headers. we need to reparse the entire // header since the change may have merged in additional values. - if (hdr == nsHttp::Cache_Control) - ParseCacheControl(mHeaders.PeekHeader(hdr)); - else if (hdr == nsHttp::Pragma) - ParsePragma(mHeaders.PeekHeader(hdr)); + if (atom == nsHttp::Cache_Control) + ParseCacheControl(mHeaders.PeekHeader(atom)); + else if (atom == nsHttp::Pragma) + ParsePragma(mHeaders.PeekHeader(atom)); return NS_OK; } @@ -316,6 +337,7 @@ nsHttpResponseHead::ParseCachedOriginalHeaders(char *block) char *p = block; nsHttpAtom hdr = {0}; + nsAutoCString headerNameOriginal; nsAutoCString val; nsresult rv; @@ -331,12 +353,13 @@ nsHttpResponseHead::ParseCachedOriginalHeaders(char *block) *p = 0; if (NS_FAILED(nsHttpHeaderArray::ParseHeaderLine( - nsDependentCString(block, p - block), &hdr, &val))) { + nsDependentCString(block, p - block), &hdr, &headerNameOriginal, &val))) { return NS_OK; } rv = mHeaders.SetResponseHeaderFromCache(hdr, + headerNameOriginal, val, nsHttpHeaderArray::eVarietyResponseNetOriginal); @@ -567,18 +590,21 @@ nsresult nsHttpResponseHead::ParseHeaderLine_locked(const nsACString &line, bool originalFromNetHeaders) { nsHttpAtom hdr = {0}; + nsAutoCString headerNameOriginal; nsAutoCString val; - if (NS_FAILED(nsHttpHeaderArray::ParseHeaderLine(line, &hdr, &val))) { + if (NS_FAILED(nsHttpHeaderArray::ParseHeaderLine(line, &hdr, &headerNameOriginal, &val))) { return NS_OK; } nsresult rv; if (originalFromNetHeaders) { rv = mHeaders.SetHeaderFromNet(hdr, + headerNameOriginal, val, true); } else { rv = mHeaders.SetResponseHeaderFromCache(hdr, + headerNameOriginal, val, nsHttpHeaderArray::eVarietyResponse); } @@ -856,7 +882,8 @@ nsHttpResponseHead::UpdateHeaders(nsHttpResponseHead *aOther) uint32_t i, count = aOther->mHeaders.Count(); for (i=0; imHeaders.PeekHeaderAt(i, header); + nsAutoCString headerNameOriginal; + const char *val = aOther->mHeaders.PeekHeaderAt(i, header, headerNameOriginal); if (!val) { continue; @@ -890,7 +917,8 @@ nsHttpResponseHead::UpdateHeaders(nsHttpResponseHead *aOther) LOG(("new response header [%s: %s]\n", header.get(), val)); // overwrite the current header value with the new value... - SetHeader_locked(header, nsDependentCString(val)); + SetHeader_locked(header, headerNameOriginal, + nsDependentCString(val)); } } diff --git a/netwerk/protocol/http/nsHttpResponseHead.h b/netwerk/protocol/http/nsHttpResponseHead.h index 0a912f4b4..8b51386ea 100644 --- a/netwerk/protocol/http/nsHttpResponseHead.h +++ b/netwerk/protocol/http/nsHttpResponseHead.h @@ -65,6 +65,8 @@ public: */ int64_t TotalEntitySize(); + nsresult SetHeader(const nsACString &h, const nsACString &v, + bool m=false); nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false); nsresult GetHeader(nsHttpAtom h, nsACString &v); void ClearHeader(nsHttpAtom h); @@ -137,8 +139,8 @@ public: bool HasContentType(); bool HasContentCharset(); private: - nsresult SetHeader_locked(nsHttpAtom h, const nsACString &v, - bool m=false); + nsresult SetHeader_locked(nsHttpAtom atom, const nsACString &h, + const nsACString &v, bool m=false); void AssignDefaultStatusText(); void ParseVersion(const char *); void ParseCacheControl(const char *); diff --git a/netwerk/test/unit/test_bug1064258.js b/netwerk/test/unit/test_bug1064258.js index 3f76837ae..da982c2d6 100644 --- a/netwerk/test/unit/test_bug1064258.js +++ b/netwerk/test/unit/test_bug1064258.js @@ -133,7 +133,7 @@ function cacheCheck2(status, entry) do_check_eq(entry.dataSize, 0); try { do_check_neq(entry.getMetaDataElement("response-head"), null); - do_check_true(entry.getMetaDataElement("response-head").match('Etag: testetag')); + do_check_true(entry.getMetaDataElement("response-head").match('etag: testetag')); } catch (ex) { do_throw("Missing response head"); diff --git a/netwerk/test/unit/test_original_sent_received_head.js b/netwerk/test/unit/test_original_sent_received_head.js index c4d02d5d2..d668abf59 100644 --- a/netwerk/test/unit/test_original_sent_received_head.js +++ b/netwerk/test/unit/test_original_sent_received_head.js @@ -114,11 +114,11 @@ function checkResponse(request, data, context) { var locationHeaderFound = 0; request.visitResponseHeaders({ visitHeader: function visit(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { linkHeaderFound++; do_check_eq(aValue, "value1, value2"); } - if (aName == "Location") { + if (aName == "location") { locationHeaderFound++; do_check_eq(aValue, "loc"); } @@ -132,7 +132,7 @@ function checkResponse(request, data, context) { var locationOrgHeaderFound = 0; request.visitOriginalResponseHeaders({ visitHeader: function visitOrg(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { if (linkOrgHeaderFound == 0) { do_check_eq(aValue, ""); } else if (linkOrgHeaderFound == 1 ) { @@ -142,7 +142,7 @@ function checkResponse(request, data, context) { } linkOrgHeaderFound++; } - if (aName == "Location") { + if (aName == "location") { locationOrgHeaderFound++; do_check_eq(aValue, "loc"); } @@ -160,10 +160,10 @@ function checkResponse(request, data, context) { var locationHeaderFound2 = 0; request.visitResponseHeaders({ visitHeader: function visit(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { linkHeaderFound2 = true; } - if (aName == "Location") { + if (aName == "location") { locationHeaderFound2 = true; } } @@ -176,7 +176,7 @@ function checkResponse(request, data, context) { var locationOrgHeaderFound2 = 0; request.visitOriginalResponseHeaders({ visitHeader: function visitOrg(aName, aValue) { - if (aName == "Link") { + if (aName == "link") { if (linkOrgHeaderFound2 == 0) { do_check_eq(aValue, ""); } else if (linkOrgHeaderFound2 == 1 ) { @@ -186,7 +186,7 @@ function checkResponse(request, data, context) { } linkOrgHeaderFound2++; } - if (aName == "Location") { + if (aName == "location") { locationOrgHeaderFound2++; do_check_eq(aValue, "loc"); } @@ -199,7 +199,7 @@ function checkResponse(request, data, context) { if (dbg) { print("============== Test GetResponseHeader"); } var linkOrgHeaderFound3 = 0; - request.getOriginalResponseHeader("Link",{ + request.getOriginalResponseHeader("link",{ visitHeader: function visitOrg(aName, aValue) { if (linkOrgHeaderFound3 == 0) { do_check_eq(aValue, ""); -- cgit v1.2.3 From 475a210a336da603f308d9163e3922b7cc285e0b Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Wed, 26 Sep 2018 18:29:45 -0400 Subject: backport mozbug 1444532 - fix a leak in SHA256 in nsHttpConnectionInfo.cpp r=mayhemer The original code (from bug 1200802) declared an XPCOM object as a static bare pointer, which for future reference is probably never the right thing to do. It might have worked if it was cleared before shutdown but it never was. --- netwerk/protocol/http/nsHttpConnectionInfo.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'netwerk') diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.cpp b/netwerk/protocol/http/nsHttpConnectionInfo.cpp index e965fd1cc..93a40843c 100644 --- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp +++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp @@ -15,32 +15,26 @@ #include "nsHttpConnectionInfo.h" #include "mozilla/net/DNS.h" -#include "prnetdb.h" -#include "nsICryptoHash.h" #include "nsComponentManagerUtils.h" +#include "nsICryptoHash.h" #include "nsIProtocolProxyService.h" +#include "nsNetCID.h" +#include "prnetdb.h" static nsresult SHA256(const char* aPlainText, nsAutoCString& aResult) { - static nsICryptoHash* hasher = nullptr; nsresult rv; - if (!hasher) { - rv = CallCreateInstance("@mozilla.org/security/hash;1", &hasher); - if (NS_FAILED(rv)) { - LOG(("nsHttpDigestAuth: no crypto hash!\n")); - return rv; - } + nsCOMPtr hasher = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + LOG(("nsHttpDigestAuth: no crypto hash!\n")); + return rv; } - rv = hasher->Init(nsICryptoHash::SHA256); NS_ENSURE_SUCCESS(rv, rv); - rv = hasher->Update((unsigned char*) aPlainText, strlen(aPlainText)); NS_ENSURE_SUCCESS(rv, rv); - - rv = hasher->Finish(false, aResult); - return rv; + return hasher->Finish(false, aResult); } namespace mozilla { -- cgit v1.2.3 From 0b16007427aac4bb94643c6ea4cc79b81010765a Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 29 Sep 2018 22:56:15 +0200 Subject: Remove telemetry to find optimal cache entry hash size Tag #21. --- netwerk/cache2/CacheIndex.cpp | 75 ---------------------------------------- netwerk/cache2/CacheIndex.h | 2 -- netwerk/cache2/CacheObserver.cpp | 29 ---------------- netwerk/cache2/CacheObserver.h | 5 --- 4 files changed, 111 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index 1009aeaf8..c85d271cc 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -20,7 +20,6 @@ #include "nsITimer.h" #include "mozilla/AutoRestore.h" #include -#include "mozilla/Telemetry.h" #include "mozilla/Unused.h" @@ -3167,11 +3166,6 @@ CacheIndex::ChangeState(EState aNewState) return; } - if ((mState == READING || mState == BUILDING || mState == UPDATING) && - aNewState == READY) { - ReportHashStats(); - } - // Try to evict entries over limit everytime we're leaving state READING, // BUILDING or UPDATING, but not during shutdown or when removing all // entries. @@ -3720,75 +3714,6 @@ CacheIndex::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) return mallocSizeOf(gInstance) + SizeOfExcludingThis(mallocSizeOf); } -namespace { - -class HashComparator -{ -public: - bool Equals(CacheIndexRecord* a, CacheIndexRecord* b) const { - return memcmp(&a->mHash, &b->mHash, sizeof(SHA1Sum::Hash)) == 0; - } - bool LessThan(CacheIndexRecord* a, CacheIndexRecord* b) const { - return memcmp(&a->mHash, &b->mHash, sizeof(SHA1Sum::Hash)) < 0; - } -}; - -void -ReportHashSizeMatch(const SHA1Sum::Hash *aHash1, const SHA1Sum::Hash *aHash2) -{ - const uint32_t *h1 = reinterpret_cast(aHash1); - const uint32_t *h2 = reinterpret_cast(aHash2); - - for (uint32_t i = 0; i < 5; ++i) { - if (h1[i] != h2[i]) { - uint32_t bitsDiff = h1[i] ^ h2[i]; - bitsDiff = NetworkEndian::readUint32(&bitsDiff); - - // count leading zeros in bitsDiff - static const uint8_t debruijn32[32] = - { 0, 31, 9, 30, 3, 8, 13, 29, 2, 5, 7, 21, 12, 24, 28, 19, - 1, 10, 4, 14, 6, 22, 25, 20, 11, 15, 23, 26, 16, 27, 17, 18}; - - bitsDiff |= bitsDiff>>1; - bitsDiff |= bitsDiff>>2; - bitsDiff |= bitsDiff>>4; - bitsDiff |= bitsDiff>>8; - bitsDiff |= bitsDiff>>16; - bitsDiff++; - - uint8_t hashSizeMatch = debruijn32[bitsDiff*0x076be629>>27] + (i<<5); - - return; - } - } - - MOZ_ASSERT(false, "Found a collision in the index!"); -} - -} // namespace - -void -CacheIndex::ReportHashStats() -{ - // We're gathering the hash stats only once, exclude too small caches. - if (CacheObserver::HashStatsReported() || mFrecencyArray.Length() < 15000) { - return; - } - - nsTArray records; - for (auto iter = mFrecencyArray.Iter(); !iter.Done(); iter.Next()) { - records.AppendElement(iter.Get()); - } - - records.Sort(HashComparator()); - - for (uint32_t i = 1; i < records.Length(); i++) { - ReportHashSizeMatch(&records[i-1]->mHash, &records[i]->mHash); - } - - CacheObserver::SetHashStatsReported(); -} - // static void CacheIndex::OnAsyncEviction(bool aEvicting) diff --git a/netwerk/cache2/CacheIndex.h b/netwerk/cache2/CacheIndex.h index dc72c346f..e51c1a0de 100644 --- a/netwerk/cache2/CacheIndex.h +++ b/netwerk/cache2/CacheIndex.h @@ -918,8 +918,6 @@ private: // Memory reporting (private part) size_t SizeOfExcludingThisInternal(mozilla::MallocSizeOf mallocSizeOf) const; - void ReportHashStats(); - static mozilla::StaticRefPtr gInstance; static StaticMutex sLock; diff --git a/netwerk/cache2/CacheObserver.cpp b/netwerk/cache2/CacheObserver.cpp index 6b6d89395..51afaf3a1 100644 --- a/netwerk/cache2/CacheObserver.cpp +++ b/netwerk/cache2/CacheObserver.cpp @@ -89,9 +89,6 @@ bool CacheObserver::sClearCacheOnShutdown = kDefaultClearCacheOnShutdown; static bool kDefaultCacheFSReported = false; bool CacheObserver::sCacheFSReported = kDefaultCacheFSReported; -static bool kDefaultHashStatsReported = false; -bool CacheObserver::sHashStatsReported = kDefaultHashStatsReported; - static uint32_t const kDefaultMaxShutdownIOLag = 2; // seconds Atomic CacheObserver::sMaxShutdownIOLag(kDefaultMaxShutdownIOLag); @@ -356,32 +353,6 @@ CacheObserver::StoreCacheFSReported() sCacheFSReported); } -// static -void -CacheObserver::SetHashStatsReported() -{ - sHashStatsReported = true; - - if (!sSelf) { - return; - } - - if (NS_IsMainThread()) { - sSelf->StoreHashStatsReported(); - } else { - nsCOMPtr event = - NewRunnableMethod(sSelf, &CacheObserver::StoreHashStatsReported); - NS_DispatchToMainThread(event); - } -} - -void -CacheObserver::StoreHashStatsReported() -{ - mozilla::Preferences::SetInt("browser.cache.disk.hashstats_reported", - sHashStatsReported); -} - // static void CacheObserver::ParentDirOverride(nsIFile** aDir) { diff --git a/netwerk/cache2/CacheObserver.h b/netwerk/cache2/CacheObserver.h index 62e5bbc6e..ee989e4d8 100644 --- a/netwerk/cache2/CacheObserver.h +++ b/netwerk/cache2/CacheObserver.h @@ -64,9 +64,6 @@ class CacheObserver : public nsIObserver static bool CacheFSReported() { return sCacheFSReported; } static void SetCacheFSReported(); - static bool HashStatsReported() - { return sHashStatsReported; } - static void SetHashStatsReported(); static void ParentDirOverride(nsIFile ** aDir); static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk); @@ -83,7 +80,6 @@ private: void StoreDiskCacheCapacity(); void StoreCacheFSReported(); - void StoreHashStatsReported(); void AttachToPreferences(); static uint32_t sUseNewCache; @@ -107,7 +103,6 @@ private: static bool sSanitizeOnShutdown; static bool sClearCacheOnShutdown; static bool sCacheFSReported; - static bool sHashStatsReported; static Atomic sMaxShutdownIOLag; static Atomic sShutdownDemandedTime; -- cgit v1.2.3 From 81b341a9b37acae2b60e0334a9b0846bc5be8445 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 29 Sep 2018 23:20:36 +0200 Subject: Clean up a number of unused variables. Tag #21. --- netwerk/base/nsSocketTransportService2.cpp | 36 ------------------------------ netwerk/base/nsUDPSocket.cpp | 6 ----- netwerk/cookie/nsCookieService.cpp | 7 ------ 3 files changed, 49 deletions(-) (limited to 'netwerk') diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 72afdc9e1..739388b0f 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -471,9 +471,6 @@ nsSocketTransportService::Poll(uint32_t *interval, PRIntervalTime ts = PR_IntervalNow(); TimeStamp pollStart; - if (mTelemetryEnabledPref) { - pollStart = TimeStamp::NowLoRes(); - } SOCKET_LOG((" timeout = %i milliseconds\n", PR_IntervalToMilliseconds(pollTimeout))); @@ -481,10 +478,6 @@ nsSocketTransportService::Poll(uint32_t *interval, PRIntervalTime passedInterval = PR_IntervalNow() - ts; - if (mTelemetryEnabledPref && !pollStart.IsNull()) { - *pollDuration = TimeStamp::NowLoRes() - pollStart; - } - SOCKET_LOG((" ...returned after %i milliseconds\n", PR_IntervalToMilliseconds(passedInterval))); @@ -858,20 +851,9 @@ nsSocketTransportService::Run() // make sure the pseudo random number generator is seeded on this thread srand(static_cast(PR_Now())); - // For the calculation of the duration of the last cycle (i.e. the last for-loop - // iteration before shutdown). - TimeStamp startOfCycleForLastCycleCalc; - int numberOfPendingEventsLastCycle; - - // For measuring of the poll iteration duration without time spent blocked - // in poll(). - TimeStamp pollCycleStart; // Time blocked in poll(). TimeDuration singlePollDuration; - // For calculating the time needed for a new element to run. - TimeStamp startOfIteration; - TimeStamp startOfNextIteration; int numberOfPendingEvents; // If there is too many pending events queued, we will run some poll() @@ -883,18 +865,9 @@ nsSocketTransportService::Run() bool pendingEvents = false; numberOfPendingEvents = 0; - numberOfPendingEventsLastCycle = 0; - if (mTelemetryEnabledPref) { - startOfCycleForLastCycleCalc = TimeStamp::NowLoRes(); - startOfNextIteration = TimeStamp::NowLoRes(); - } pollDuration = 0; do { - if (mTelemetryEnabledPref) { - pollCycleStart = TimeStamp::NowLoRes(); - } - DoPollIteration(&singlePollDuration); mRawThread->HasPendingEvents(&pendingEvents); @@ -909,15 +882,6 @@ nsSocketTransportService::Run() } else { mServingPendingQueue = true; } - - if (mTelemetryEnabledPref) { - startOfIteration = startOfNextIteration; - // Everything that comes after this point will - // be served in the next iteration. If no even - // arrives, startOfNextIteration will be reset at the - // beginning of each for-loop. - startOfNextIteration = TimeStamp::NowLoRes(); - } } TimeStamp eventQueueStart = TimeStamp::NowLoRes(); do { diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index 24f3954cb..445b62d9c 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -770,12 +770,6 @@ nsUDPSocket::CloseSocket() // If shutdown last to long, let the socket leak and do not close it. UDPSOCKET_LOG(("Intentional leak")); } else { - - PRIntervalTime closeStarted = 0; - if (gSocketTransportService->IsTelemetryEnabledAndNotSleepPhase()) { - closeStarted = PR_IntervalNow(); - } - PR_Close(mFD); } mFD = nullptr; diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index ea54dbd61..7bc5abcd1 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -3311,13 +3311,6 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI, // so we can handle them separately. bool newCookie = ParseAttributes(aCookieHeader, cookieAttributes); - // Collect telemetry on how often secure cookies are set from non-secure - // origins, and vice-versa. - // - // 0 = nonsecure and "http:" - // 1 = nonsecure and "https:" - // 2 = secure and "http:" - // 3 = secure and "https:" bool isHTTPS; nsresult rv = aHostURI->SchemeIs("https", &isHTTPS); -- cgit v1.2.3 From 3343a4b4744b6c78d1f3d0c3f111e1adfddc18a5 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 29 Sep 2018 23:55:49 +0200 Subject: Remove telemetry probes for cache file system. --- netwerk/cache2/CacheFileIOManager.cpp | 48 ----------------------------------- netwerk/cache2/CacheObserver.cpp | 29 --------------------- netwerk/cache2/CacheObserver.h | 5 ---- 3 files changed, 82 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache2/CacheFileIOManager.cpp b/netwerk/cache2/CacheFileIOManager.cpp index f6b499e47..25e621d12 100644 --- a/netwerk/cache2/CacheFileIOManager.cpp +++ b/netwerk/cache2/CacheFileIOManager.cpp @@ -3822,44 +3822,6 @@ CacheFileIOManager::CreateCacheTree() StartRemovingTrash(); - if (!CacheObserver::CacheFSReported()) { - uint32_t fsType = 4; // Other OS - -#ifdef XP_WIN - nsAutoString target; - nsresult rv = mCacheDirectory->GetTarget(target); - if (NS_FAILED(rv)) { - return NS_OK; - } - - wchar_t volume_path[MAX_PATH + 1] = { 0 }; - if (!::GetVolumePathNameW(target.get(), - volume_path, - mozilla::ArrayLength(volume_path))) { - return NS_OK; - } - - wchar_t fsName[6] = { 0 }; - if (!::GetVolumeInformationW(volume_path, nullptr, 0, nullptr, nullptr, - nullptr, fsName, - mozilla::ArrayLength(fsName))) { - return NS_OK; - } - - if (wcscmp(fsName, L"NTFS") == 0) { - fsType = 0; - } else if (wcscmp(fsName, L"FAT32") == 0) { - fsType = 1; - } else if (wcscmp(fsName, L"FAT") == 0) { - fsType = 2; - } else { - fsType = 3; - } -#endif - - CacheObserver::SetCacheFSReported(); - } - return NS_OK; } @@ -3905,16 +3867,6 @@ CacheFileIOManager::OpenNSPRHandle(CacheFileHandle *aHandle, bool aCreate) LOG(("CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry" " with hash %08x%08x%08x%08x%08x. %s to create the new file.", LOGSHA1(&hash), NS_SUCCEEDED(rv) ? "Succeeded" : "Failed")); - - // Report the full size only once per session - static bool sSizeReported = false; - if (!sSizeReported) { - uint32_t cacheUsage; - if (NS_SUCCEEDED(CacheIndex::GetCacheSize(&cacheUsage))) { - cacheUsage >>= 10; - sSizeReported = true; - } - } } else { LOG(("CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing" " entry.")); diff --git a/netwerk/cache2/CacheObserver.cpp b/netwerk/cache2/CacheObserver.cpp index 51afaf3a1..32e0dff95 100644 --- a/netwerk/cache2/CacheObserver.cpp +++ b/netwerk/cache2/CacheObserver.cpp @@ -86,9 +86,6 @@ bool CacheObserver::sSanitizeOnShutdown = kDefaultSanitizeOnShutdown; static bool kDefaultClearCacheOnShutdown = false; bool CacheObserver::sClearCacheOnShutdown = kDefaultClearCacheOnShutdown; -static bool kDefaultCacheFSReported = false; -bool CacheObserver::sCacheFSReported = kDefaultCacheFSReported; - static uint32_t const kDefaultMaxShutdownIOLag = 2; // seconds Atomic CacheObserver::sMaxShutdownIOLag(kDefaultMaxShutdownIOLag); @@ -327,32 +324,6 @@ CacheObserver::StoreDiskCacheCapacity() sDiskCacheCapacity); } -// static -void -CacheObserver::SetCacheFSReported() -{ - sCacheFSReported = true; - - if (!sSelf) { - return; - } - - if (NS_IsMainThread()) { - sSelf->StoreCacheFSReported(); - } else { - nsCOMPtr event = - NewRunnableMethod(sSelf, &CacheObserver::StoreCacheFSReported); - NS_DispatchToMainThread(event); - } -} - -void -CacheObserver::StoreCacheFSReported() -{ - mozilla::Preferences::SetInt("browser.cache.disk.filesystem_reported", - sCacheFSReported); -} - // static void CacheObserver::ParentDirOverride(nsIFile** aDir) { diff --git a/netwerk/cache2/CacheObserver.h b/netwerk/cache2/CacheObserver.h index ee989e4d8..ccdd89030 100644 --- a/netwerk/cache2/CacheObserver.h +++ b/netwerk/cache2/CacheObserver.h @@ -61,9 +61,6 @@ class CacheObserver : public nsIObserver { return sHalfLifeExperiment; } static bool ClearCacheOnShutdown() { return sSanitizeOnShutdown && sClearCacheOnShutdown; } - static bool CacheFSReported() - { return sCacheFSReported; } - static void SetCacheFSReported(); static void ParentDirOverride(nsIFile ** aDir); static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk); @@ -79,7 +76,6 @@ private: static CacheObserver* sSelf; void StoreDiskCacheCapacity(); - void StoreCacheFSReported(); void AttachToPreferences(); static uint32_t sUseNewCache; @@ -102,7 +98,6 @@ private: static int32_t sHalfLifeExperiment; static bool sSanitizeOnShutdown; static bool sClearCacheOnShutdown; - static bool sCacheFSReported; static Atomic sMaxShutdownIOLag; static Atomic sShutdownDemandedTime; -- cgit v1.2.3 From ab9edfb54bb985e683c318bbd7e4c3594d8e6df2 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 30 Sep 2018 04:39:37 +0200 Subject: Remove telemetry probes to get detailed disk cache hit rate. Tag #21. --- netwerk/cache2/CacheEntry.cpp | 15 ------- netwerk/cache2/CacheFileUtils.cpp | 95 --------------------------------------- netwerk/cache2/CacheFileUtils.h | 59 ------------------------ netwerk/cache2/CacheIndex.cpp | 23 ---------- netwerk/cache2/CacheIndex.h | 3 -- 5 files changed, 195 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache2/CacheEntry.cpp b/netwerk/cache2/CacheEntry.cpp index b79bf7373..51e441aa7 100644 --- a/netwerk/cache2/CacheEntry.cpp +++ b/netwerk/cache2/CacheEntry.cpp @@ -419,11 +419,6 @@ bool CacheEntry::Load(bool aTruncate, bool aPriority) { mozilla::MutexAutoUnlock unlock(mLock); - if (reportMiss) { - CacheFileUtils::DetailedCacheHitTelemetry::AddRecord( - CacheFileUtils::DetailedCacheHitTelemetry::MISS, mLoadStart); - } - LOG((" performing load, file=%p", mFile.get())); if (NS_SUCCEEDED(rv)) { rv = mFile->Init(fileKey, @@ -458,16 +453,6 @@ NS_IMETHODIMP CacheEntry::OnFileReady(nsresult aResult, bool aIsNew) MOZ_ASSERT(!mLoadStart.IsNull()); - if (NS_SUCCEEDED(aResult)) { - if (aIsNew) { - CacheFileUtils::DetailedCacheHitTelemetry::AddRecord( - CacheFileUtils::DetailedCacheHitTelemetry::MISS, mLoadStart); - } else { - CacheFileUtils::DetailedCacheHitTelemetry::AddRecord( - CacheFileUtils::DetailedCacheHitTelemetry::HIT, mLoadStart); - } - } - // OnFileReady, that is the only code that can transit from LOADING // to any follow-on state and can only be invoked ones on an entry. // Until this moment there is no consumer that could manipulate diff --git a/netwerk/cache2/CacheFileUtils.cpp b/netwerk/cache2/CacheFileUtils.cpp index fe1a53b3d..a090a9cb1 100644 --- a/netwerk/cache2/CacheFileUtils.cpp +++ b/netwerk/cache2/CacheFileUtils.cpp @@ -401,101 +401,6 @@ ValidityMap::operator[](uint32_t aIdx) return mMap.ElementAt(aIdx); } -StaticMutex DetailedCacheHitTelemetry::sLock; -uint32_t DetailedCacheHitTelemetry::sRecordCnt = 0; -DetailedCacheHitTelemetry::HitRate DetailedCacheHitTelemetry::sHRStats[kNumOfRanges]; - -DetailedCacheHitTelemetry::HitRate::HitRate() -{ - Reset(); -} - -void -DetailedCacheHitTelemetry::HitRate::AddRecord(ERecType aType) -{ - if (aType == HIT) { - ++mHitCnt; - } else { - ++mMissCnt; - } -} - -uint32_t -DetailedCacheHitTelemetry::HitRate::GetHitRateBucket(uint32_t aNumOfBuckets) const -{ - uint32_t bucketIdx = (aNumOfBuckets * mHitCnt) / (mHitCnt + mMissCnt); - if (bucketIdx == aNumOfBuckets) { // make sure 100% falls into the last bucket - --bucketIdx; - } - - return bucketIdx; -} - -uint32_t -DetailedCacheHitTelemetry::HitRate::Count() -{ - return mHitCnt + mMissCnt; -} - -void -DetailedCacheHitTelemetry::HitRate::Reset() -{ - mHitCnt = 0; - mMissCnt = 0; -} - -// static -void -DetailedCacheHitTelemetry::AddRecord(ERecType aType, TimeStamp aLoadStart) -{ - bool isUpToDate = false; - CacheIndex::IsUpToDate(&isUpToDate); - if (!isUpToDate) { - // Ignore the record when the entry file count might be incorrect - return; - } - - uint32_t entryCount; - nsresult rv = CacheIndex::GetEntryFileCount(&entryCount); - if (NS_FAILED(rv)) { - return; - } - - uint32_t rangeIdx = entryCount / kRangeSize; - if (rangeIdx >= kNumOfRanges) { // The last range has no upper limit. - rangeIdx = kNumOfRanges - 1; - } - - uint32_t hitMissValue = 2 * rangeIdx; // 2 values per range - if (aType == MISS) { // The order is HIT, MISS - ++hitMissValue; - } - - StaticMutexAutoLock lock(sLock); - - sHRStats[rangeIdx].AddRecord(aType); - ++sRecordCnt; - - if (sRecordCnt < kTotalSamplesReportLimit) { - return; - } - - sRecordCnt = 0; - - for (uint32_t i = 0; i < kNumOfRanges; ++i) { - if (sHRStats[i].Count() >= kHitRateSamplesReportLimit) { - // The telemetry enums are grouped by buckets as follows: - // Telemetry value : 0,1,2,3, ... ,19,20,21,22, ... ,398,399 - // Hit rate bucket : 0,0,0,0, ... , 0, 1, 1, 1, ... , 19, 19 - // Cache size range: 0,1,2,3, ... ,19, 0, 1, 2, ... , 18, 19 - uint32_t bucketOffset = sHRStats[i].GetHitRateBucket(kHitRateBuckets) * - kNumOfRanges; - - sHRStats[i].Reset(); - } - } -} - void FreeBuffer(void *aBuf) { #ifndef NS_FREE_PERMANENT_DATA diff --git a/netwerk/cache2/CacheFileUtils.h b/netwerk/cache2/CacheFileUtils.h index 13acfd71d..b66f0adf1 100644 --- a/netwerk/cache2/CacheFileUtils.h +++ b/netwerk/cache2/CacheFileUtils.h @@ -10,7 +10,6 @@ #include "nsString.h" #include "nsTArray.h" #include "mozilla/StaticMutex.h" -#include "mozilla/TimeStamp.h" class nsILoadContextInfo; class nsACString; @@ -90,64 +89,6 @@ private: nsTArray mMap; }; - -class DetailedCacheHitTelemetry { -public: - enum ERecType { - HIT = 0, - MISS = 1 - }; - - static void AddRecord(ERecType aType, TimeStamp aLoadStart); - -private: - class HitRate { - public: - HitRate(); - - void AddRecord(ERecType aType); - // Returns the bucket index that the current hit rate falls into according - // to the given aNumOfBuckets. - uint32_t GetHitRateBucket(uint32_t aNumOfBuckets) const; - uint32_t Count(); - void Reset(); - - private: - uint32_t mHitCnt; - uint32_t mMissCnt; - }; - - // Group the hits and misses statistics by cache files count ranges (0-5000, - // 5001-10000, ... , 95001- ) - static const uint32_t kRangeSize = 5000; - static const uint32_t kNumOfRanges = 20; - - // Use the same ranges to report an average hit rate. Report the hit rates - // (and reset the counters) every kTotalSamplesReportLimit samples. - static const uint32_t kTotalSamplesReportLimit = 1000; - - // Report hit rate for a given cache size range only if it contains - // kHitRateSamplesReportLimit or more samples. This limit should avoid - // reporting a biased statistics. - static const uint32_t kHitRateSamplesReportLimit = 500; - - // All hit rates are accumulated in a single telemetry probe, so to use - // a sane number of enumerated values the hit rate is divided into buckets - // instead of using a percent value. This constant defines number of buckets - // that we divide the hit rates into. I.e. we'll report ranges 0%-5%, 5%-10%, - // 10-%15%, ... - static const uint32_t kHitRateBuckets = 20; - - // Protects sRecordCnt and sHitStats calls. - static StaticMutex sLock; - - // Counter of samples that is compared against kTotalSamplesReportLimit. - static uint32_t sRecordCnt; - - // Hit rate statistics for every cache size range. - static HitRate sHRStats[kNumOfRanges]; -}; - void FreeBuffer(void *aBuf); diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index c85d271cc..2c6451d72 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -1292,29 +1292,6 @@ CacheIndex::GetCacheSize(uint32_t *_retval) return NS_OK; } -// static -nsresult -CacheIndex::GetEntryFileCount(uint32_t *_retval) -{ - LOG(("CacheIndex::GetEntryFileCount()")); - - StaticMutexAutoLock lock(sLock); - - RefPtr index = gInstance; - - if (!index) { - return NS_ERROR_NOT_INITIALIZED; - } - - if (!index->IsIndexUsable()) { - return NS_ERROR_NOT_AVAILABLE; - } - - *_retval = index->mIndexStats.ActiveEntriesCount(); - LOG(("CacheIndex::GetEntryFileCount() - returning %u", *_retval)); - return NS_OK; -} - // static nsresult CacheIndex::GetCacheStats(nsILoadContextInfo *aInfo, uint32_t *aSize, uint32_t *aCount) diff --git a/netwerk/cache2/CacheIndex.h b/netwerk/cache2/CacheIndex.h index e51c1a0de..acb3bdd25 100644 --- a/netwerk/cache2/CacheIndex.h +++ b/netwerk/cache2/CacheIndex.h @@ -662,9 +662,6 @@ public: // Returns cache size in kB. static nsresult GetCacheSize(uint32_t *_retval); - // Returns number of entry files in the cache - static nsresult GetEntryFileCount(uint32_t *_retval); - // Synchronously returns the disk occupation and number of entries per-context. // Callable on any thread. static nsresult GetCacheStats(nsILoadContextInfo *aInfo, uint32_t *aSize, uint32_t *aCount); -- cgit v1.2.3 From 8ba6dd1bd12a3d13f9e2c683216dd8778011a72e Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 30 Sep 2018 06:56:29 +0200 Subject: Remove cache I/O telemetry. Tag #21. --- netwerk/cache2/CacheIOThread.cpp | 54 ---------------------------------------- 1 file changed, 54 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache2/CacheIOThread.cpp b/netwerk/cache2/CacheIOThread.cpp index d51f61b0f..2fbc0ccce 100644 --- a/netwerk/cache2/CacheIOThread.cpp +++ b/netwerk/cache2/CacheIOThread.cpp @@ -18,54 +18,6 @@ namespace mozilla { namespace net { -namespace { // anon - -class CacheIOTelemetry -{ -public: - typedef CacheIOThread::EventQueue::size_type size_type; - static size_type mMinLengthToReport[CacheIOThread::LAST_LEVEL]; - static void Report(uint32_t aLevel, size_type aLength); -}; - -static CacheIOTelemetry::size_type const kGranularity = 30; - -CacheIOTelemetry::size_type -CacheIOTelemetry::mMinLengthToReport[CacheIOThread::LAST_LEVEL] = { - kGranularity, kGranularity, kGranularity, kGranularity, - kGranularity, kGranularity, kGranularity, kGranularity -}; - -// static -void CacheIOTelemetry::Report(uint32_t aLevel, CacheIOTelemetry::size_type aLength) -{ - if (mMinLengthToReport[aLevel] > aLength) { - return; - } - - static Telemetry::ID telemetryID[] = { - Telemetry::HTTP_CACHE_IO_QUEUE_2_OPEN_PRIORITY, - Telemetry::HTTP_CACHE_IO_QUEUE_2_READ_PRIORITY, - Telemetry::HTTP_CACHE_IO_QUEUE_2_MANAGEMENT, - Telemetry::HTTP_CACHE_IO_QUEUE_2_OPEN, - Telemetry::HTTP_CACHE_IO_QUEUE_2_READ, - Telemetry::HTTP_CACHE_IO_QUEUE_2_WRITE_PRIORITY, - Telemetry::HTTP_CACHE_IO_QUEUE_2_WRITE, - Telemetry::HTTP_CACHE_IO_QUEUE_2_INDEX, - Telemetry::HTTP_CACHE_IO_QUEUE_2_EVICT - }; - - // Each bucket is a multiply of kGranularity (30, 60, 90..., 300+) - aLength = (aLength / kGranularity); - // Next time report only when over the current length + kGranularity - mMinLengthToReport[aLevel] = (aLength + 1) * kGranularity; - - // 10 is number of buckets we have in each probe - aLength = std::min(aLength, 10); -} - -} // anon - namespace detail { /** @@ -525,7 +477,6 @@ void CacheIOThread::LoopOneLevel(uint32_t aLevel) mCurrentlyExecutingLevel = aLevel; bool returnEvents = false; - bool reportTelementry = true; EventQueue::size_type index; { @@ -539,11 +490,6 @@ void CacheIOThread::LoopOneLevel(uint32_t aLevel) break; } - if (reportTelementry) { - reportTelementry = false; - CacheIOTelemetry::Report(aLevel, length); - } - // Drop any previous flagging, only an event on the current level may set // this flag. mRerunCurrentEvent = false; -- cgit v1.2.3 From 7b0f3f2f92a22df1b3d4a4a35bab2a5c637d3cb4 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 1 Oct 2018 11:00:05 +0200 Subject: Remove unused telemetry functions/variables. Tag #21. --- netwerk/cache2/CacheFile.cpp | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache2/CacheFile.cpp b/netwerk/cache2/CacheFile.cpp index ce771c754..69fc3d33c 100644 --- a/netwerk/cache2/CacheFile.cpp +++ b/netwerk/cache2/CacheFile.cpp @@ -1865,33 +1865,6 @@ CacheFile::Truncate(int64_t aOffset) return NS_OK; } -static uint32_t -StatusToTelemetryEnum(nsresult aStatus) -{ - if (NS_SUCCEEDED(aStatus)) { - return 0; - } - - switch (aStatus) { - case NS_BASE_STREAM_CLOSED: - return 0; // Log this as a success - case NS_ERROR_OUT_OF_MEMORY: - return 2; - case NS_ERROR_FILE_DISK_FULL: - return 3; - case NS_ERROR_FILE_CORRUPTED: - return 4; - case NS_ERROR_FILE_NOT_FOUND: - return 5; - case NS_BINDING_ABORTED: - return 6; - default: - return 1; // other error - } - - NS_NOTREACHED("We should never get here"); -} - nsresult CacheFile::RemoveInput(CacheFileInputStream *aInput, nsresult aStatus) { -- cgit v1.2.3 From d718e32b522ebc06f3093df72a3409a3d2fe046e Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 1 Oct 2018 11:01:01 +0200 Subject: Remove telemetry from cache v1 service locking (part1). Tag #21. --- netwerk/cache/nsCacheService.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache/nsCacheService.cpp b/netwerk/cache/nsCacheService.cpp index 97b1a71c8..414887970 100644 --- a/netwerk/cache/nsCacheService.cpp +++ b/netwerk/cache/nsCacheService.cpp @@ -2640,17 +2640,8 @@ nsCacheService::Lock() void nsCacheService::Lock(mozilla::Telemetry::ID mainThreadLockerID) { - mozilla::Telemetry::ID lockerID; - mozilla::Telemetry::ID generalID; - - if (NS_IsMainThread()) { - lockerID = mainThreadLockerID; - generalID = mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_2; - } else { - lockerID = mozilla::Telemetry::HistogramCount; - generalID = mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_2; - } - + // Telemetry data removed. + // XXX: Fold into nsCacheService::Lock() nsCacheService::Lock(); } -- cgit v1.2.3 From ec4c6dd42abcbf6fd081ce3da1dbf1b5ea9c0d8f Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 1 Oct 2018 11:31:29 +0200 Subject: Remove telemetry from cache v1 service locking (part2). - Fold Lock(TelemetryID) into Lock(); - Fold nsCacheServiceAutoLock(TelemetryID) into nsCacheServiceAutoLock(); Tag #21. --- netwerk/cache/nsCacheEntryDescriptor.cpp | 83 ++++++++++++++++---------------- netwerk/cache/nsCacheService.cpp | 57 +++++++++------------- netwerk/cache/nsCacheService.h | 6 --- 3 files changed, 65 insertions(+), 81 deletions(-) (limited to 'netwerk') diff --git a/netwerk/cache/nsCacheEntryDescriptor.cpp b/netwerk/cache/nsCacheEntryDescriptor.cpp index 64765f8aa..35ea22d55 100644 --- a/netwerk/cache/nsCacheEntryDescriptor.cpp +++ b/netwerk/cache/nsCacheEntryDescriptor.cpp @@ -43,7 +43,7 @@ public: nsresult status = NS_OK; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSASYNCDOOMEVENT_RUN)); + nsCacheServiceAutoLock lock; if (mDescriptor->mCacheEntry) { status = nsCacheService::gService->DoomEntry_Internal( @@ -113,7 +113,7 @@ nsCacheEntryDescriptor::GetClientID(char ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCLIENTID)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return ClientIDFromCacheKey(*(mCacheEntry->Key()), result); @@ -124,7 +124,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID) { NS_ENSURE_ARG_POINTER(aDeviceID); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDEVICEID)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; const char* deviceID = mCacheEntry->GetDeviceID(); @@ -141,7 +141,7 @@ nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID) NS_IMETHODIMP nsCacheEntryDescriptor::GetKey(nsACString &result) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETKEY)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result); @@ -152,7 +152,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetFetchCount(int32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETFETCHCOUNT)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->FetchCount(); @@ -164,7 +164,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetLastFetched(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETLASTFETCHED)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->LastFetched(); @@ -176,7 +176,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetLastModified(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETLASTMODIFIED)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->LastModified(); @@ -188,7 +188,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetExpirationTime(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETEXPIRATIONTIME)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->ExpirationTime(); @@ -199,7 +199,7 @@ nsCacheEntryDescriptor::GetExpirationTime(uint32_t *result) NS_IMETHODIMP nsCacheEntryDescriptor::SetExpirationTime(uint32_t expirationTime) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETEXPIRATIONTIME)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; mCacheEntry->SetExpirationTime(expirationTime); @@ -211,7 +211,7 @@ nsCacheEntryDescriptor::SetExpirationTime(uint32_t expirationTime) NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(bool *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_ISSTREAMBASED)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->IsStreamData(); @@ -221,7 +221,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(bool *result) NS_IMETHODIMP nsCacheEntryDescriptor::GetPredictedDataSize(int64_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETPREDICTEDDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->PredictedDataSize(); @@ -231,7 +231,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetPredictedDataSize(int64_t *result) NS_IMETHODIMP nsCacheEntryDescriptor::SetPredictedDataSize(int64_t predictedSize) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETPREDICTEDDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; mCacheEntry->SetPredictedDataSize(predictedSize); @@ -241,7 +241,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::SetPredictedDataSize(int64_t NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; const char* val = mCacheEntry->GetMetaDataElement("uncompressed-len"); @@ -258,7 +258,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(uint32_t *result) NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(uint32_t *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->DataSize(); @@ -270,7 +270,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(uint32_t *result) nsresult nsCacheEntryDescriptor::RequestDataSizeChange(int32_t deltaSize) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_REQUESTDATASIZECHANGE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; nsresult rv; @@ -288,7 +288,7 @@ nsCacheEntryDescriptor::RequestDataSizeChange(int32_t deltaSize) NS_IMETHODIMP nsCacheEntryDescriptor::SetDataSize(uint32_t dataSize) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETDATASIZE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // XXX review for signed/unsigned math errors @@ -317,7 +317,7 @@ nsCacheEntryDescriptor::OpenInputStream(uint32_t offset, nsIInputStream ** resul nsInputStreamWrapper* cacheInput = nullptr; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_OPENINPUTSTREAM)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM; @@ -352,7 +352,7 @@ nsCacheEntryDescriptor::OpenOutputStream(uint32_t offset, nsIOutputStream ** res nsOutputStreamWrapper* cacheOutput = nullptr; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_OPENOUTPUTSTREAM)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM; @@ -390,7 +390,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCACHEELEMENT)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM; @@ -402,7 +402,7 @@ nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result) NS_IMETHODIMP nsCacheEntryDescriptor::SetCacheElement(nsISupports * cacheElement) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETCACHEELEMENT)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM; @@ -423,7 +423,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSTORAGEPOLICY)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->StoragePolicy(); @@ -434,7 +434,7 @@ nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result) NS_IMETHODIMP nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETSTORAGEPOLICY)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // XXX validate policy against session? @@ -461,7 +461,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetFile(nsIFile ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETFILE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return nsCacheService::GetFileForEntry(mCacheEntry, result); @@ -472,7 +472,7 @@ NS_IMETHODIMP nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result) { NS_ENSURE_ARG_POINTER(result); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETSECURITYINFO)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; *result = mCacheEntry->SecurityInfo(); @@ -484,7 +484,7 @@ nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result) NS_IMETHODIMP nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETSECURITYINFO)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; mCacheEntry->SetSecurityInfo(securityInfo); @@ -496,7 +496,7 @@ nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo) NS_IMETHODIMP nsCacheEntryDescriptor::Doom() { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_DOOM)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return nsCacheService::DoomEntry(mCacheEntry); @@ -506,7 +506,7 @@ nsCacheEntryDescriptor::Doom() NS_IMETHODIMP nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_DOOMANDFAILPENDINGREQUESTS)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_IMPLEMENTED; @@ -544,7 +544,7 @@ nsCacheEntryDescriptor::AsyncDoom(nsICacheListener *listener) NS_IMETHODIMP nsCacheEntryDescriptor::MarkValid() { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_MARKVALID)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; nsresult rv = nsCacheService::ValidateEntry(mCacheEntry); @@ -559,7 +559,7 @@ nsCacheEntryDescriptor::Close() nsTArray > inputWrappers; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // Make sure no other stream can be opened @@ -585,7 +585,7 @@ nsCacheEntryDescriptor::Close() inputWrappers.Clear(); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE)); + nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; // XXX perhaps closing descriptors should clear/sever transports @@ -604,7 +604,7 @@ nsCacheEntryDescriptor::GetMetaDataElement(const char *key, char **result) NS_ENSURE_ARG_POINTER(key); *result = nullptr; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETMETADATAELEMENT)); + nsCacheServiceAutoLock lock; NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE); const char *value; @@ -624,7 +624,7 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value) { NS_ENSURE_ARG_POINTER(key); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_SETMETADATAELEMENT)); + nsCacheServiceAutoLock lock; NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_AVAILABLE); // XXX allow null value, for clearing key? @@ -639,7 +639,7 @@ nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value) NS_IMETHODIMP nsCacheEntryDescriptor::VisitMetaData(nsICacheMetaDataVisitor * visitor) { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_VISITMETADATA)); + nsCacheServiceAutoLock lock; // XXX check callers, we're calling out of module NS_ENSURE_ARG_POINTER(visitor); if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; @@ -667,7 +667,7 @@ nsCacheEntryDescriptor::nsInputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); @@ -709,7 +709,7 @@ nsInputStreamWrapper::LazyInit() if (!mDescriptor) return NS_ERROR_NOT_AVAILABLE; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_LAZYINIT)); + nsCacheServiceAutoLock lock; nsCacheAccessMode mode; nsresult rv = mDescriptor->GetAccessGranted(&mode); @@ -755,7 +755,7 @@ nsInputStreamWrapper::CloseInternal() return; } - nsCacheServiceAutoLock lock(LOCK_TELEM(NSINPUTSTREAMWRAPPER_CLOSEINTERNAL)); + nsCacheServiceAutoLock lock; if (mDescriptor) { mDescriptor->mInputWrappers.RemoveElement(this); @@ -859,8 +859,7 @@ nsCacheEntryDescriptor::nsDecompressInputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM( - NSDECOMPRESSINPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); @@ -1049,7 +1048,7 @@ nsCacheEntryDescriptor::nsOutputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); @@ -1089,7 +1088,7 @@ nsOutputStreamWrapper::LazyInit() if (!mDescriptor) return NS_ERROR_NOT_AVAILABLE; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_LAZYINIT)); + nsCacheServiceAutoLock lock; nsCacheAccessMode mode; nsresult rv = mDescriptor->GetAccessGranted(&mode); @@ -1163,7 +1162,7 @@ nsOutputStreamWrapper::CloseInternal() return; } - nsCacheServiceAutoLock lock(LOCK_TELEM(NSOUTPUTSTREAMWRAPPER_CLOSEINTERNAL)); + nsCacheServiceAutoLock lock; if (mDescriptor) { mDescriptor->mOutputWrapper = nullptr; @@ -1279,7 +1278,7 @@ nsCacheEntryDescriptor::nsCompressOutputStreamWrapper::Release() } if (desc) - nsCacheService::Lock(LOCK_TELEM(NSCOMPRESSOUTPUTSTREAMWRAPPER_RELEASE)); + nsCacheService::Lock(); nsrefcnt count; NS_PRECONDITION(0 != mRefCnt, "dup release"); diff --git a/netwerk/cache/nsCacheService.cpp b/netwerk/cache/nsCacheService.cpp index 414887970..4b08614b8 100644 --- a/netwerk/cache/nsCacheService.cpp +++ b/netwerk/cache/nsCacheService.cpp @@ -211,7 +211,7 @@ public: NS_IMETHOD Notify(nsITimer* aTimer) override { if (nsCacheService::gService) { - nsCacheServiceAutoLock autoLock(LOCK_TELEM(NSSETDISKSMARTSIZECALLBACK_NOTIFY)); + nsCacheServiceAutoLock autoLock; nsCacheService::gService->SetDiskSmartSize_Locked(); nsCacheService::gService->mSmartSizeTimer = nullptr; } @@ -295,7 +295,7 @@ public: } NS_IMETHOD Run() override { - nsCacheServiceAutoLock autoLock(LOCK_TELEM(NSBLOCKONCACHETHREADEVENT_RUN)); + nsCacheServiceAutoLock autoLock; CACHE_LOG_DEBUG(("nsBlockOnCacheThreadEvent [%p]\n", this)); nsCacheService::gService->mNotified = true; nsCacheService::gService->mCondVar.Notify(); @@ -988,7 +988,7 @@ public: NS_ASSERTION(mRequest->mListener, "Sync OpenCacheEntry() posted to background thread!"); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSPROCESSREQUESTEVENT_RUN)); + nsCacheServiceAutoLock lock; rv = nsCacheService::gService->ProcessRequest(mRequest, false, nullptr); @@ -1189,7 +1189,7 @@ nsCacheService::Shutdown() nsCOMPtr parentDir; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SHUTDOWN)); + nsCacheServiceAutoLock lock; NS_ASSERTION(mInitialized, "can't shutdown nsCacheService unless it has been initialized."); if (!mInitialized) @@ -1204,7 +1204,7 @@ nsCacheService::Shutdown() UnregisterWeakMemoryReporter(this); { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SHUTDOWN)); + nsCacheServiceAutoLock lock; NS_ASSERTION(mInitialized, "Bad state"); mInitialized = false; @@ -1363,7 +1363,7 @@ nsCacheService::EvictEntriesForClient(const char * clientID, new EvictionNotifierRunnable(NS_ISUPPORTS_CAST(nsICacheService*, this)); NS_DispatchToMainThread(r); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_EVICTENTRIESFORCLIENT)); + nsCacheServiceAutoLock lock; nsresult res = NS_OK; if (storagePolicy == nsICache::STORE_ANYWHERE || @@ -1412,7 +1412,7 @@ nsCacheService::IsStorageEnabledForPolicy(nsCacheStoragePolicy storagePolicy, bool * result) { if (gService == nullptr) return NS_ERROR_NOT_AVAILABLE; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ISSTORAGEENABLEDFORPOLICY)); + nsCacheServiceAutoLock lock; *result = gService->IsStorageEnabledForPolicy_Locked(storagePolicy); return NS_OK; @@ -1466,7 +1466,7 @@ nsresult nsCacheService::VisitEntriesInternal(nsICacheVisitor *visitor) { NS_ENSURE_ARG_POINTER(visitor); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_VISITENTRIES)); + nsCacheServiceAutoLock lock; if (!(mEnableDiskDevice || mEnableMemoryDevice)) return NS_ERROR_NOT_AVAILABLE; @@ -1548,7 +1548,7 @@ NS_IMETHODIMP nsCacheService::GetCacheIOTarget(nsIEventTarget * *aCacheIOTarget) // read from the main thread without the lock. This is useful to prevent // blocking the main thread on other cache operations. if (!NS_IsMainThread()) { - Lock(LOCK_TELEM(NSCACHESERVICE_GETCACHEIOTARGET)); + Lock(); } nsresult rv; @@ -1940,7 +1940,7 @@ nsCacheService::ProcessRequest(nsCacheRequest * request, // XXX this is probably wrong... Unlock(); rv = request->WaitForValidation(); - Lock(LOCK_TELEM(NSCACHESERVICE_PROCESSREQUEST)); + Lock(); } PR_REMOVE_AND_INIT_LINK(request); @@ -2052,7 +2052,7 @@ nsCacheService::OpenCacheEntry(nsCacheSession * session, } else { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_OPENCACHEENTRY)); + nsCacheServiceAutoLock lock; rv = gService->ProcessRequest(request, true, result); // delete requests that have completed @@ -2353,14 +2353,14 @@ nsCacheService::OnProfileShutdown() } { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILESHUTDOWN)); + nsCacheServiceAutoLock lock; gService->mClearingEntries = true; gService->DoomActiveEntries(nullptr); } gService->CloseAllStreams(); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILESHUTDOWN)); + nsCacheServiceAutoLock lock; gService->ClearDoomList(); // Make sure to wait for any pending cache-operations before @@ -2399,7 +2399,7 @@ nsCacheService::OnProfileChanged() CACHE_LOG_DEBUG(("nsCacheService::OnProfileChanged")); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILECHANGED)); + nsCacheServiceAutoLock lock; gService->mEnableDiskDevice = gService->mObserver->DiskCacheEnabled(); gService->mEnableOfflineDevice = gService->mObserver->OfflineCacheEnabled(); @@ -2453,7 +2453,7 @@ void nsCacheService::SetDiskCacheEnabled(bool enabled) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEENABLED)); + nsCacheServiceAutoLock lock; gService->mEnableDiskDevice = enabled; } @@ -2462,7 +2462,7 @@ void nsCacheService::SetDiskCacheCapacity(int32_t capacity) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHECAPACITY)); + nsCacheServiceAutoLock lock; if (gService->mDiskDevice) { gService->mDiskDevice->SetCapacity(capacity); @@ -2475,7 +2475,7 @@ void nsCacheService::SetDiskCacheMaxEntrySize(int32_t maxSize) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEMAXENTRYSIZE)); + nsCacheServiceAutoLock lock; if (gService->mDiskDevice) { gService->mDiskDevice->SetMaxEntrySize(maxSize); @@ -2486,7 +2486,7 @@ void nsCacheService::SetMemoryCacheMaxEntrySize(int32_t maxSize) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHEMAXENTRYSIZE)); + nsCacheServiceAutoLock lock; if (gService->mMemoryDevice) { gService->mMemoryDevice->SetMaxEntrySize(maxSize); @@ -2497,7 +2497,7 @@ void nsCacheService::SetOfflineCacheEnabled(bool enabled) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHEENABLED)); + nsCacheServiceAutoLock lock; gService->mEnableOfflineDevice = enabled; } @@ -2505,7 +2505,7 @@ void nsCacheService::SetOfflineCacheCapacity(int32_t capacity) { if (!gService) return; - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHECAPACITY)); + nsCacheServiceAutoLock lock; if (gService->mOfflineDevice) { gService->mOfflineDevice->SetCapacity(capacity); @@ -2522,7 +2522,7 @@ nsCacheService::SetMemoryCache() CACHE_LOG_DEBUG(("nsCacheService::SetMemoryCache")); - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHE)); + nsCacheServiceAutoLock lock; gService->mEnableMemoryDevice = gService->mObserver->MemoryCacheEnabled(); @@ -2637,14 +2637,6 @@ nsCacheService::Lock() gService->LockAcquired(); } -void -nsCacheService::Lock(mozilla::Telemetry::ID mainThreadLockerID) -{ - // Telemetry data removed. - // XXX: Fold into nsCacheService::Lock() - nsCacheService::Lock(); -} - void nsCacheService::Unlock() { @@ -2924,7 +2916,7 @@ nsCacheService::CloseAllStreams() nsTArray > outputs; { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_CLOSEALLSTREAMS)); + nsCacheServiceAutoLock lock; nsTArray entries; @@ -3047,7 +3039,7 @@ nsCacheService::LogCacheStatistics() nsresult nsCacheService::SetDiskSmartSize() { - nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKSMARTSIZE)); + nsCacheServiceAutoLock lock; if (!gService) return NS_ERROR_NOT_AVAILABLE; @@ -3166,8 +3158,7 @@ nsCacheService::CollectReports(nsIHandleReportCallback* aHandleReport, { size_t disk = 0; if (mDiskDevice) { - nsCacheServiceAutoLock - lock(LOCK_TELEM(NSCACHESERVICE_DISKDEVICEHEAPSIZE)); + nsCacheServiceAutoLock lock; disk = mDiskDevice->SizeOfIncludingThis(DiskCacheDeviceMallocSizeOf); } diff --git a/netwerk/cache/nsCacheService.h b/netwerk/cache/nsCacheService.h index 1751d4875..95816cfe5 100644 --- a/netwerk/cache/nsCacheService.h +++ b/netwerk/cache/nsCacheService.h @@ -371,9 +371,6 @@ private: * nsCacheServiceAutoLock ******************************************************************************/ -#define LOCK_TELEM(x) \ - (::mozilla::Telemetry::CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_##x) - // Instantiate this class to acquire the cache service lock for a particular // execution scope. class nsCacheServiceAutoLock { @@ -381,9 +378,6 @@ public: nsCacheServiceAutoLock() { nsCacheService::Lock(); } - explicit nsCacheServiceAutoLock(mozilla::Telemetry::ID mainThreadLockerID) { - nsCacheService::Lock(mainThreadLockerID); - } ~nsCacheServiceAutoLock() { nsCacheService::Unlock(); } -- cgit v1.2.3 From dbac7d6914a2a370bca54f9912dbfeaee2182584 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Mon, 22 Oct 2018 21:28:24 -0400 Subject: backport m-c bug 1333174 - Don't use NS_ENSURE_SUCCESS at nsIOService:793 Log spam fix. Suppresses 1,100 instances of NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80520012 emitted from netwerk/base/nsIOService.cpp during linux64 debug testing. Backports [m-c 1333174](https://bugzilla.mozilla.org/show_bug.cgi?id=1333174). --- netwerk/base/nsIOService.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'netwerk') diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index e13541acf..435294315 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -789,7 +789,9 @@ nsIOService::NewChannelFromURIWithProxyFlagsInternal(nsIURI* aURI, // creating a new channel by calling NewChannel(). if (NS_FAILED(rv)) { rv = handler->NewChannel(aURI, getter_AddRefs(channel)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + return rv; + } // The protocol handler does not implement NewChannel2, so // maybe we need to wrap the channel (see comment in MaybeWrap // function). -- cgit v1.2.3 From e4cc27a0e791be3d504ed91355a9ea03711f2aa5 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 23 Oct 2018 20:28:01 -0400 Subject: backport m-c bug 1333172 - Avoid 1100 warnings by replacing NS_ENSURE_SUCCESS in nsNetUtilInlines.h:180 --- netwerk/base/nsNetUtilInlines.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'netwerk') diff --git a/netwerk/base/nsNetUtilInlines.h b/netwerk/base/nsNetUtilInlines.h index 7003814d5..b831ec2e7 100644 --- a/netwerk/base/nsNetUtilInlines.h +++ b/netwerk/base/nsNetUtilInlines.h @@ -224,7 +224,9 @@ NS_NewChannelInternal(nsIChannel **outChannel, aUri, aLoadInfo, getter_AddRefs(channel)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + return rv; + } if (aLoadGroup) { rv = channel->SetLoadGroup(aLoadGroup); -- cgit v1.2.3 From a2a8c71d7774858db67f51b9c475c5b1d4e43e8f Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Thu, 1 Nov 2018 07:31:23 +0100 Subject: Make HTTP/2 compressor more resilient to bad data. --- netwerk/protocol/http/Http2Compression.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'netwerk') diff --git a/netwerk/protocol/http/Http2Compression.cpp b/netwerk/protocol/http/Http2Compression.cpp index 64fd05a17..9206f8b4c 100644 --- a/netwerk/protocol/http/Http2Compression.cpp +++ b/netwerk/protocol/http/Http2Compression.cpp @@ -402,7 +402,7 @@ Http2Decompressor::DecodeHeaderBlock(const uint8_t *data, uint32_t datalen, nsresult rv = NS_OK; nsresult softfail_rv = NS_OK; - while (NS_SUCCEEDED(rv) && (mOffset < datalen)) { + while (NS_SUCCEEDED(rv) && (mOffset < mDataLen)) { bool modifiesTable = true; if (mData[mOffset] & 0x80) { rv = DoIndexed(); @@ -684,6 +684,11 @@ nsresult Http2Decompressor::DecodeFinalHuffmanCharacter(const HuffmanIncomingTable *table, uint8_t &c, uint8_t &bitsLeft) { + MOZ_ASSERT(mOffset <= mDataLen); + if (mOffset > mDataLen) { + NS_WARNING("DecodeFinalHuffmanCharacter trying to read beyond end of buffer"); + return NS_ERROR_FAILURE; + } uint8_t mask = (1 << bitsLeft) - 1; uint8_t idx = mData[mOffset - 1] & mask; idx <<= (8 - bitsLeft); @@ -721,6 +726,7 @@ Http2Decompressor::DecodeFinalHuffmanCharacter(const HuffmanIncomingTable *table uint8_t Http2Decompressor::ExtractByte(uint8_t bitsLeft, uint32_t &bytesConsumed) { + MOZ_DIAGNOSTIC_ASSERT(mOffset < mDataLen); uint8_t rv; if (bitsLeft) { @@ -750,8 +756,8 @@ Http2Decompressor::DecodeHuffmanCharacter(const HuffmanIncomingTable *table, uint8_t idx = ExtractByte(bitsLeft, bytesConsumed); if (table->IndexHasANextTable(idx)) { - if (bytesConsumed >= mDataLen) { - if (!bitsLeft || (bytesConsumed > mDataLen)) { + if (mOffset >= mDataLen) { + if (!bitsLeft || (mOffset > mDataLen)) { // TODO - does this get me into trouble in the new world? // No info left in input to try to consume, we're done LOG(("DecodeHuffmanCharacter all out of bits to consume, can't chain")); @@ -892,6 +898,13 @@ Http2Decompressor::DoLiteralInternal(nsACString &name, nsACString &value, return rv; } + // sanity check + if (mOffset >= mDataLen) { + NS_WARNING("Http2 Decompressor ran out of data"); + // This is session-fatal + return NS_ERROR_FAILURE; + } + bool isHuffmanEncoded; if (!index) { @@ -919,6 +932,13 @@ Http2Decompressor::DoLiteralInternal(nsACString &name, nsACString &value, return rv; } + // sanity check + if (mOffset >= mDataLen) { + NS_WARNING("Http2 Decompressor ran out of data"); + // This is session-fatal + return NS_ERROR_FAILURE; + } + // now the value uint32_t valueLen; isHuffmanEncoded = mData[mOffset] & (1 << 7); -- cgit v1.2.3 From 059397bdd2b8eaaa7f2bbacb9ce415aba8db91b0 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Thu, 1 Nov 2018 22:14:07 +0100 Subject: Remove Query/Ref from the directory listing URI. Port of Bug 1488061. --- netwerk/streamconv/converters/nsIndexedToHTML.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'netwerk') diff --git a/netwerk/streamconv/converters/nsIndexedToHTML.cpp b/netwerk/streamconv/converters/nsIndexedToHTML.cpp index 0414c4841..29fea8bfb 100644 --- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp +++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp @@ -146,7 +146,14 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, nsAutoCString baseUri, titleUri; rv = uri->GetAsciiSpec(baseUri); if (NS_FAILED(rv)) return rv; - titleUri = baseUri; + + nsCOMPtr titleURL; + rv = uri->Clone(getter_AddRefs(titleURL)); + if (NS_FAILED(rv)) titleURL = uri; + rv = titleURL->SetQuery(EmptyCString()); + if (NS_FAILED(rv)) titleURL = uri; + rv = titleURL->SetRef(EmptyCString()); + if (NS_FAILED(rv)) titleURL = uri; nsCString parentStr; @@ -170,16 +177,14 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, // that - see above nsAutoCString pw; - rv = uri->GetPassword(pw); + rv = titleURL->GetPassword(pw); if (NS_FAILED(rv)) return rv; if (!pw.IsEmpty()) { nsCOMPtr newUri; - rv = uri->Clone(getter_AddRefs(newUri)); + rv = titleURL->Clone(getter_AddRefs(newUri)); if (NS_FAILED(rv)) return rv; rv = newUri->SetPassword(EmptyCString()); if (NS_FAILED(rv)) return rv; - rv = newUri->GetAsciiSpec(titleUri); - if (NS_FAILED(rv)) return rv; } nsAutoCString path; @@ -247,6 +252,11 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, } } + rv = titleURL->GetAsciiSpec(titleUri); + if (NS_FAILED(rv)) { + return rv; + } + buffer.AppendLiteral("