| Index: mojo/public/cpp/bindings/lib/message_header_validator.cc
|
| diff --git a/mojo/public/cpp/bindings/lib/message_header_validator.cc b/mojo/public/cpp/bindings/lib/message_header_validator.cc
|
| index 940b15ccf2c14994f7346d1cd0a645ce33295c50..638279820bf79d7c86b0964fe82fda167622240a 100644
|
| --- a/mojo/public/cpp/bindings/lib/message_header_validator.cc
|
| +++ b/mojo/public/cpp/bindings/lib/message_header_validator.cc
|
| @@ -4,7 +4,7 @@
|
|
|
| #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
|
|
|
| -#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
|
| +#include "mojo/public/cpp/bindings/lib/validation_context.h"
|
| #include "mojo/public/cpp/bindings/lib/validation_errors.h"
|
| #include "mojo/public/cpp/bindings/lib/validation_util.h"
|
|
|
| @@ -12,24 +12,28 @@ namespace mojo {
|
| namespace internal {
|
| namespace {
|
|
|
| -bool IsValidMessageHeader(const MessageHeader* header) {
|
| +bool IsValidMessageHeader(const MessageHeader* header,
|
| + ValidationContext* validation_context) {
|
| // NOTE: Our goal is to preserve support for future extension of the message
|
| // header. If we encounter fields we do not understand, we must ignore them.
|
|
|
| // Extra validation of the struct header:
|
| if (header->version == 0) {
|
| if (header->num_bytes != sizeof(MessageHeader)) {
|
| - ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| return false;
|
| }
|
| } else if (header->version == 1) {
|
| if (header->num_bytes != sizeof(MessageHeaderWithRequestID)) {
|
| - ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| return false;
|
| }
|
| } else if (header->version > 1) {
|
| if (header->num_bytes < sizeof(MessageHeaderWithRequestID)) {
|
| - ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| return false;
|
| }
|
| }
|
| @@ -39,14 +43,16 @@ bool IsValidMessageHeader(const MessageHeader* header) {
|
| // These flags require a RequestID.
|
| if (header->version < 1 && ((header->flags & kMessageExpectsResponse) ||
|
| (header->flags & kMessageIsResponse))) {
|
| - ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID);
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID);
|
| return false;
|
| }
|
|
|
| // These flags are mutually exclusive.
|
| if ((header->flags & kMessageExpectsResponse) &&
|
| (header->flags & kMessageIsResponse)) {
|
| - ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| return false;
|
| }
|
|
|
| @@ -56,18 +62,27 @@ bool IsValidMessageHeader(const MessageHeader* header) {
|
| } // namespace
|
|
|
| MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink)
|
| - : MessageFilter(sink) {
|
| + : MessageHeaderValidator("MessageHeaderValidator", sink) {}
|
| +
|
| +MessageHeaderValidator::MessageHeaderValidator(const std::string& description,
|
| + MessageReceiver* sink)
|
| + : MessageFilter(sink), description_(description) {
|
| +}
|
| +
|
| +void MessageHeaderValidator::SetDescription(const std::string& description) {
|
| + description_ = description;
|
| }
|
|
|
| bool MessageHeaderValidator::Accept(Message* message) {
|
| // Pass 0 as number of handles because we don't expect any in the header, even
|
| // if |message| contains handles.
|
| - BoundsChecker bounds_checker(message->data(), message->data_num_bytes(), 0);
|
| + ValidationContext validation_context(
|
| + message->data(), message->data_num_bytes(), 0, message, description_);
|
|
|
| - if (!ValidateStructHeaderAndClaimMemory(message->data(), &bounds_checker))
|
| + if (!ValidateStructHeaderAndClaimMemory(message->data(), &validation_context))
|
| return false;
|
|
|
| - if (!IsValidMessageHeader(message->header()))
|
| + if (!IsValidMessageHeader(message->header(), &validation_context))
|
| return false;
|
|
|
| return sink_->Accept(message);
|
|
|