| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 5 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | 7 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" |
| 8 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 8 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| 9 #include "mojo/public/cpp/bindings/lib/validation_util.h" | 9 #include "mojo/public/cpp/bindings/lib/validation_util.h" |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS); | 49 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS); |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink) | 58 MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink) |
| 59 : MessageFilter(sink) { | 59 : MessageHeaderValidator(sink, "Unknown header validator") {} |
| 60 } | |
| 61 | 60 |
| 62 bool MessageHeaderValidator::Accept(Message* message) { | 61 MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink, |
| 62 const std::string& debug_info) |
| 63 : MessageFilter(sink), debug_info_(debug_info) {} |
| 64 |
| 65 bool MessageHeaderValidator::Accept(Message* message, Error* error) { |
| 63 // Pass 0 as number of handles because we don't expect any in the header, even | 66 // Pass 0 as number of handles because we don't expect any in the header, even |
| 64 // if |message| contains handles. | 67 // if |message| contains handles. |
| 65 BoundsChecker bounds_checker(message->data(), message->data_num_bytes(), 0); | 68 BoundsChecker bounds_checker(message->data(), message->data_num_bytes(), 0); |
| 66 | 69 |
| 67 if (!ValidateStructHeaderAndClaimMemory(message->data(), &bounds_checker)) | 70 if (!ValidateStructHeaderAndClaimMemory(message->data(), &bounds_checker)) { |
| 71 *error = Error::ForBadMessage(debug_info_, message); |
| 68 return false; | 72 return false; |
| 73 } |
| 69 | 74 |
| 70 if (!IsValidMessageHeader(message->header())) | 75 if (!IsValidMessageHeader(message->header())) { |
| 76 *error = Error::ForBadMessage(debug_info_, message); |
| 71 return false; | 77 return false; |
| 78 } |
| 72 | 79 |
| 73 return sink_->Accept(message); | 80 return sink_->Accept(message, error); |
| 74 } | 81 } |
| 75 | 82 |
| 76 } // namespace internal | 83 } // namespace internal |
| 77 } // namespace mojo | 84 } // namespace mojo |
| OLD | NEW |