Bug 1434206 - Clear the current table when protocol parser is done. r?gcp
Add assertions in the functions that don't already test for
mTableUpdate just to be extra-safe.
MozReview-Commit-ID: 8R67SLSgj23
--- a/toolkit/components/url-classifier/ProtocolParser.cpp
+++ b/toolkit/components/url-classifier/ProtocolParser.cpp
@@ -180,16 +180,17 @@ ProtocolParserV2::AppendStream(const nsA
}
return NS_OK;
}
void
ProtocolParserV2::End()
{
// Inbound data has already been processed in every AppendStream() call.
+ mTableUpdate = nullptr;
}
nsresult
ProtocolParserV2::ProcessControl(bool* aDone)
{
nsresult rv;
nsAutoCString line;
@@ -518,16 +519,17 @@ ProtocolParserV2::ProcessDigestChunk(con
return ProcessDigestSub(aChunk);
}
return NS_ERROR_UNEXPECTED;
}
nsresult
ProtocolParserV2::ProcessDigestAdd(const nsACString& aChunk)
{
+ MOZ_ASSERT(mTableUpdate);
// The ABNF format for add chunks is (HASH)+, where HASH is 32 bytes.
MOZ_ASSERT(aChunk.Length() % 32 == 0,
"Chunk length in bytes must be divisible by 4");
uint32_t start = 0;
while (start < aChunk.Length()) {
Completion hash;
hash.Assign(Substring(aChunk, start, COMPLETE_SIZE));
start += COMPLETE_SIZE;
@@ -537,16 +539,17 @@ ProtocolParserV2::ProcessDigestAdd(const
}
}
return NS_OK;
}
nsresult
ProtocolParserV2::ProcessDigestSub(const nsACString& aChunk)
{
+ MOZ_ASSERT(mTableUpdate);
// The ABNF format for sub chunks is (ADDCHUNKNUM HASH)+, where ADDCHUNKNUM
// is a 4 byte chunk number, and HASH is 32 bytes.
MOZ_ASSERT(aChunk.Length() % 36 == 0,
"Chunk length in bytes must be divisible by 36");
uint32_t start = 0;
while (start < aChunk.Length()) {
// Read ADDCHUNKNUM
const nsACString& addChunkStr = Substring(aChunk, start, 4);
@@ -568,16 +571,17 @@ ProtocolParserV2::ProcessDigestSub(const
}
return NS_OK;
}
nsresult
ProtocolParserV2::ProcessHostAdd(const Prefix& aDomain, uint8_t aNumEntries,
const nsACString& aChunk, uint32_t* aStart)
{
+ MOZ_ASSERT(mTableUpdate);
NS_ASSERTION(mChunkState.hashSize == PREFIX_SIZE,
"ProcessHostAdd should only be called for prefix hashes.");
if (aNumEntries == 0) {
nsresult rv = mTableUpdate->NewAddPrefix(mChunkState.num, aDomain);
if (NS_FAILED(rv)) {
return rv;
}
@@ -602,16 +606,17 @@ ProtocolParserV2::ProcessHostAdd(const P
return NS_OK;
}
nsresult
ProtocolParserV2::ProcessHostSub(const Prefix& aDomain, uint8_t aNumEntries,
const nsACString& aChunk, uint32_t *aStart)
{
+ MOZ_ASSERT(mTableUpdate);
NS_ASSERTION(mChunkState.hashSize == PREFIX_SIZE,
"ProcessHostSub should only be called for prefix hashes.");
if (aNumEntries == 0) {
if ((*aStart) + 4 > aChunk.Length()) {
NS_WARNING("Received a zero-entry sub chunk without an associated add.");
return NS_ERROR_FAILURE;
}
@@ -657,16 +662,17 @@ ProtocolParserV2::ProcessHostSub(const P
return NS_OK;
}
nsresult
ProtocolParserV2::ProcessHostAddComplete(uint8_t aNumEntries,
const nsACString& aChunk, uint32_t* aStart)
{
+ MOZ_ASSERT(mTableUpdate);
NS_ASSERTION(mChunkState.hashSize == COMPLETE_SIZE,
"ProcessHostAddComplete should only be called for complete hashes.");
if (aNumEntries == 0) {
// this is totally comprehensible.
// My sarcasm detector is going off!
NS_WARNING("Expected > 0 entries for a 32-byte hash add.");
return NS_OK;
@@ -689,16 +695,17 @@ ProtocolParserV2::ProcessHostAddComplete
return NS_OK;
}
nsresult
ProtocolParserV2::ProcessHostSubComplete(uint8_t aNumEntries,
const nsACString& aChunk, uint32_t* aStart)
{
+ MOZ_ASSERT(mTableUpdate);
NS_ASSERTION(mChunkState.hashSize == COMPLETE_SIZE,
"ProcessHostSubComplete should only be called for complete hashes.");
if (aNumEntries == 0) {
// this is totally comprehensible.
NS_WARNING("Expected > 0 entries for a 32-byte hash sub.");
return NS_OK;
}