| 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 638279820bf79d7c86b0964fe82fda167622240a..10f7774130169c852f1f98b88a6d64ed0c7aeb0f 100644
|
| --- a/mojo/public/cpp/bindings/lib/message_header_validator.cc
|
| +++ b/mojo/public/cpp/bindings/lib/message_header_validator.cc
|
| @@ -2,38 +2,40 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
|
| +#include "mojo/public/cpp/bindings/message_header_validator.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"
|
|
|
| namespace mojo {
|
| -namespace internal {
|
| namespace {
|
|
|
| -bool IsValidMessageHeader(const MessageHeader* header,
|
| - ValidationContext* validation_context) {
|
| +bool IsValidMessageHeader(const internal::MessageHeader* header,
|
| + internal::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_context,
|
| - VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| + if (header->num_bytes != sizeof(internal::MessageHeader)) {
|
| + internal::ReportValidationError(
|
| + validation_context,
|
| + internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| return false;
|
| }
|
| } else if (header->version == 1) {
|
| - if (header->num_bytes != sizeof(MessageHeaderWithRequestID)) {
|
| - ReportValidationError(validation_context,
|
| - VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| + if (header->num_bytes != sizeof(internal::MessageHeaderWithRequestID)) {
|
| + internal::ReportValidationError(
|
| + validation_context,
|
| + internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| return false;
|
| }
|
| } else if (header->version > 1) {
|
| - if (header->num_bytes < sizeof(MessageHeaderWithRequestID)) {
|
| - ReportValidationError(validation_context,
|
| - VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| + if (header->num_bytes < sizeof(internal::MessageHeaderWithRequestID)) {
|
| + internal::ReportValidationError(
|
| + validation_context,
|
| + internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
| return false;
|
| }
|
| }
|
| @@ -41,18 +43,20 @@ bool IsValidMessageHeader(const MessageHeader* header,
|
| // Validate flags (allow unknown bits):
|
|
|
| // These flags require a RequestID.
|
| - if (header->version < 1 && ((header->flags & kMessageExpectsResponse) ||
|
| - (header->flags & kMessageIsResponse))) {
|
| - ReportValidationError(validation_context,
|
| - VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID);
|
| + if (header->version < 1 && ((header->flags & Message::kFlagExpectsResponse) ||
|
| + (header->flags & Message::kFlagIsResponse))) {
|
| + internal::ReportValidationError(
|
| + validation_context,
|
| + internal::VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID);
|
| return false;
|
| }
|
|
|
| // These flags are mutually exclusive.
|
| - if ((header->flags & kMessageExpectsResponse) &&
|
| - (header->flags & kMessageIsResponse)) {
|
| - ReportValidationError(validation_context,
|
| - VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| + if ((header->flags & Message::kFlagExpectsResponse) &&
|
| + (header->flags & Message::kFlagIsResponse)) {
|
| + internal::ReportValidationError(
|
| + validation_context,
|
| + internal::VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| return false;
|
| }
|
|
|
| @@ -76,10 +80,11 @@ void MessageHeaderValidator::SetDescription(const std::string& 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.
|
| - ValidationContext validation_context(
|
| + internal::ValidationContext validation_context(
|
| message->data(), message->data_num_bytes(), 0, message, description_);
|
|
|
| - if (!ValidateStructHeaderAndClaimMemory(message->data(), &validation_context))
|
| + if (!internal::ValidateStructHeaderAndClaimMemory(message->data(),
|
| + &validation_context))
|
| return false;
|
|
|
| if (!IsValidMessageHeader(message->header(), &validation_context))
|
| @@ -88,5 +93,4 @@ bool MessageHeaderValidator::Accept(Message* message) {
|
| return sink_->Accept(message);
|
| }
|
|
|
| -} // namespace internal
|
| } // namespace mojo
|
|
|