Bug 1434662 - Reset Safe Browsing V4 tables that fail to update. r=gcp

This is a generalization of the reset code that's used in pver2
to reset all tables when a `pleasereset` command is received.

MozReview-Commit-ID: LF4RegQHqoT
This commit is contained in:
Francois Marier
2018-04-12 10:11:30 -07:00
parent 3e7c2254f2
commit cac0e90920
3 changed files with 27 additions and 17 deletions

View File

@@ -113,7 +113,6 @@ ProtocolParser::GetTableUpdate(const nsACString& aTable)
ProtocolParserV2::ProtocolParserV2()
: mState(PROTOCOL_STATE_CONTROL)
, mResetRequested(false)
, mTableUpdate(nullptr)
{
}
@@ -188,7 +187,8 @@ ProtocolParserV2::ProcessControl(bool* aDone)
return NS_ERROR_FAILURE;
}
} else if (line.EqualsLiteral("r:pleasereset")) {
mResetRequested = true;
PARSER_LOG(("All tables will be reset."));
mTablesToReset = mRequestedTables;
} else if (StringBeginsWith(line, NS_LITERAL_CSTRING("u:"))) {
rv = ProcessForward(line);
NS_ENSURE_SUCCESS(rv, rv);
@@ -780,21 +780,29 @@ ProtocolParserProtobuf::End()
for (int i = 0; i < response.list_update_responses_size(); i++) {
auto r = response.list_update_responses(i);
nsresult rv = ProcessOneResponse(r);
nsAutoCString listName;
nsresult rv = ProcessOneResponse(r, listName);
if (NS_SUCCEEDED(rv)) {
mUpdateStatus = rv;
} else {
nsAutoCString errorName;
mozilla::GetErrorName(rv, errorName);
NS_WARNING(nsPrintfCString("Failed to process one response: %s",
errorName.get()).get());
NS_WARNING(nsPrintfCString("Failed to process one response for '%s': %s",
listName.get(), errorName.get()).get());
if (!listName.IsEmpty()) {
PARSER_LOG(("Table %s will be reset.", listName.get()));
mTablesToReset.AppendElement(listName);
}
}
}
}
nsresult
ProtocolParserProtobuf::ProcessOneResponse(const ListUpdateResponse& aResponse)
ProtocolParserProtobuf::ProcessOneResponse(const ListUpdateResponse& aResponse,
nsACString& aListName)
{
MOZ_ASSERT(aListName.IsEmpty());
// A response must have a threat type.
if (!aResponse.has_threat_type()) {
NS_WARNING("Threat type not initialized. This seems to be an invalid response.");
@@ -816,17 +824,16 @@ ProtocolParserProtobuf::ProcessOneResponse(const ListUpdateResponse& aResponse)
// Match the table name we received with one of the ones we requested.
// We ignore the case where a threat type matches more than one list
// per provider and return the first one. See bug 1287059."
nsCString listName;
nsTArray<nsCString> possibleListNameArray;
Classifier::SplitTables(possibleListNames, possibleListNameArray);
for (auto possibleName : possibleListNameArray) {
if (mRequestedTables.Contains(possibleName)) {
listName = possibleName;
aListName = possibleName;
break;
}
}
if (listName.IsEmpty()) {
if (aListName.IsEmpty()) {
PARSER_LOG(("We received an update for a list we didn't ask for. Ignoring it."));
return NS_ERROR_FAILURE;
}
@@ -847,7 +854,7 @@ ProtocolParserProtobuf::ProcessOneResponse(const ListUpdateResponse& aResponse)
return NS_ERROR_UC_PARSER_MISSING_PARAM;
}
auto tu = GetTableUpdate(nsCString(listName.get()));
auto tu = GetTableUpdate(aListName);
auto tuV4 = TableUpdate::Cast<TableUpdateV4>(tu);
NS_ENSURE_TRUE(tuV4, NS_ERROR_FAILURE);
@@ -860,7 +867,7 @@ ProtocolParserProtobuf::ProcessOneResponse(const ListUpdateResponse& aResponse)
}
PARSER_LOG(("==== Update for threat type '%d' ====", aResponse.threat_type()));
PARSER_LOG(("* listName: %s\n", listName.get()));
PARSER_LOG(("* aListName: %s\n", PromiseFlatCString(aListName).get()));
PARSER_LOG(("* newState: %s\n", aResponse.new_client_state().c_str()));
PARSER_LOG(("* isFullUpdate: %s\n", (isFullUpdate ? "yes" : "no")));
PARSER_LOG(("* hasChecksum: %s\n", (aResponse.has_checksum() ? "yes" : "no")));