Bug 1439468 - Improve error reporting in Safe Browsing protocol parser. r?gcp
MozReview-Commit-ID: JeyCZSbdZBd
--- a/toolkit/components/url-classifier/ProtocolParser.cpp
+++ b/toolkit/components/url-classifier/ProtocolParser.cpp
@@ -11,16 +11,17 @@
#include "prprf.h"
#include "nsUrlClassifierDBService.h"
#include "nsUrlClassifierUtils.h"
#include "nsPrintfCString.h"
#include "mozilla/Base64.h"
#include "RiceDeltaDecoder.h"
#include "mozilla/EndianUtils.h"
+#include "mozilla/ErrorNames.h"
#include "mozilla/IntegerPrintfMacros.h"
// MOZ_LOG=UrlClassifierProtocolParser:5
mozilla::LazyLogModule gUrlClassifierProtocolParserLog("UrlClassifierProtocolParser");
#define PARSER_LOG(args) MOZ_LOG(gUrlClassifierProtocolParserLog, mozilla::LogLevel::Debug, args)
namespace mozilla {
namespace safebrowsing {
@@ -778,40 +779,43 @@ ProtocolParserProtobuf::End()
minWaitDuration.nanos() / 1000000000;
for (int i = 0; i < response.list_update_responses_size(); i++) {
auto r = response.list_update_responses(i);
nsresult rv = ProcessOneResponse(r);
if (NS_SUCCEEDED(rv)) {
mUpdateStatus = rv;
} else {
- NS_WARNING("Failed to process one response.");
+ nsAutoCString errorName;
+ mozilla::GetErrorName(rv, errorName);
+ NS_WARNING(nsPrintfCString("Failed to process one response: %s",
+ errorName.get()).get());
}
}
}
nsresult
ProtocolParserProtobuf::ProcessOneResponse(const ListUpdateResponse& aResponse)
{
// 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.");
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_PARSER_MISSING_PARAM;
}
// Convert threat type to list name.
nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
nsCString possibleListNames;
nsresult rv = urlUtil->ConvertThreatTypeToListNames(aResponse.threat_type(),
possibleListNames);
if (NS_FAILED(rv)) {
PARSER_LOG(("Threat type to list name conversion error: %d",
aResponse.threat_type()));
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_PARSER_UNKNOWN_THREAT;
}
// 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);
@@ -829,23 +833,23 @@ ProtocolParserProtobuf::ProcessOneRespon
// Test if this is a full update.
bool isFullUpdate = false;
if (aResponse.has_response_type()) {
isFullUpdate =
aResponse.response_type() == ListUpdateResponse::FULL_UPDATE;
} else {
NS_WARNING("Response type not initialized.");
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_PARSER_MISSING_PARAM;
}
// Warn if there's no new state.
if (!aResponse.has_new_client_state()) {
NS_WARNING("New state not initialized.");
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_PARSER_MISSING_PARAM;
}
auto tu = GetTableUpdate(nsCString(listName.get()));
auto tuV4 = TableUpdate::Cast<TableUpdateV4>(tu);
NS_ENSURE_TRUE(tuV4, NS_ERROR_FAILURE);
nsCString state(aResponse.new_client_state().c_str(),
aResponse.new_client_state().size());
@@ -973,22 +977,22 @@ ProtocolParserProtobuf::ProcessRawRemova
}
static nsresult
DoRiceDeltaDecode(const RiceDeltaEncoding& aEncoding,
nsTArray<uint32_t>& aDecoded)
{
if (!aEncoding.has_first_value()) {
PARSER_LOG(("The encoding info is incomplete."));
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_PARSER_MISSING_PARAM;
}
if (aEncoding.num_entries() > 0 &&
(!aEncoding.has_rice_parameter() || !aEncoding.has_encoded_data())) {
PARSER_LOG(("Rice parameter or encoded data is missing."));
- return NS_ERROR_FAILURE;
+ return NS_ERROR_UC_PARSER_MISSING_PARAM;
}
PARSER_LOG(("* Encoding info:"));
PARSER_LOG((" - First value: %" PRId64, aEncoding.first_value()));
PARSER_LOG((" - Num of entries: %d", aEncoding.num_entries()));
PARSER_LOG((" - Rice parameter: %d", aEncoding.rice_parameter()));
// Set up the input buffer. Note that the bits should be read
@@ -1005,17 +1009,17 @@ DoRiceDeltaDecode(const RiceDeltaEncodin
}
// Decode!
bool rv = decoder.Decode(aEncoding.rice_parameter(),
aEncoding.first_value(), // first value.
aEncoding.num_entries(), // # of entries (first value not included).
&aDecoded[0]);
- NS_ENSURE_TRUE(rv, NS_ERROR_FAILURE);
+ NS_ENSURE_TRUE(rv, NS_ERROR_UC_PARSER_DECODE_FAILURE);
return NS_OK;
}
nsresult
ProtocolParserProtobuf::ProcessEncodedAddition(TableUpdateV4& aTableUpdate,
const ThreatEntrySet& aAddition)
{
old mode 100644
new mode 100755
--- a/xpcom/base/ErrorList.py
+++ b/xpcom/base/ErrorList.py
@@ -1088,28 +1088,34 @@ with modules["DOM_MEDIA"]:
# Internal platform-related errors
errors["NS_ERROR_DOM_MEDIA_CUBEB_INITIALIZATION_ERR"] = FAILURE(101)
# =======================================================================
# 42: NS_ERROR_MODULE_URL_CLASSIFIER
# =======================================================================
with modules["URL_CLASSIFIER"]:
+ # Errors during list updates
errors["NS_ERROR_UC_UPDATE_UNKNOWN"] = FAILURE(1)
errors["NS_ERROR_UC_UPDATE_DUPLICATE_PREFIX"] = FAILURE(2)
errors["NS_ERROR_UC_UPDATE_INFINITE_LOOP"] = FAILURE(3)
errors["NS_ERROR_UC_UPDATE_WRONG_REMOVAL_INDICES"] = FAILURE(4)
errors["NS_ERROR_UC_UPDATE_CHECKSUM_MISMATCH"] = FAILURE(5)
errors["NS_ERROR_UC_UPDATE_MISSING_CHECKSUM"] = FAILURE(6)
errors["NS_ERROR_UC_UPDATE_SHUTDOWNING"] = FAILURE(7)
errors["NS_ERROR_UC_UPDATE_TABLE_NOT_FOUND"] = FAILURE(8)
errors["NS_ERROR_UC_UPDATE_BUILD_PREFIX_FAILURE"] = FAILURE(9)
errors["NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK"] = FAILURE(10)
errors["NS_ERROR_UC_UPDATE_PROTOCOL_PARSER_ERROR"] = FAILURE(11)
+ # Specific errors while parsing pver2/pver4 responses
+ errors["NS_ERROR_UC_PARSER_MISSING_PARAM"] = FAILURE(12)
+ errors["NS_ERROR_UC_PARSER_DECODE_FAILURE"] = FAILURE(13)
+ errors["NS_ERROR_UC_PARSER_UNKNOWN_THREAT"] = FAILURE(14)
+
# =======================================================================
# 43: NS_ERROR_MODULE_ERRORRESULT
# =======================================================================
with modules["ERRORRESULT"]:
# Represents a JS Value being thrown as an exception.
errors["NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION"] = FAILURE(1)
# Used to indicate that we want to throw a DOMException.