| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/validation_util.h" | 5 #include "mojo/public/cpp/bindings/lib/validation_util.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" | 9 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" |
| 10 #include "mojo/public/cpp/bindings/lib/message_internal.h" | |
| 11 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 10 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| 12 | 11 |
| 13 namespace mojo { | 12 namespace mojo { |
| 14 namespace internal { | 13 namespace internal { |
| 15 | 14 |
| 16 bool ValidateEncodedPointer(const uint64_t* offset) { | 15 bool ValidateEncodedPointer(const uint64_t* offset) { |
| 17 // - Make sure |*offset| is no more than 32-bits. | 16 // - Make sure |*offset| is no more than 32-bits. |
| 18 // - Cast |offset| to uintptr_t so overflow behavior is well defined across | 17 // - Cast |offset| to uintptr_t so overflow behavior is well defined across |
| 19 // 32-bit and 64-bit systems. | 18 // 32-bit and 64-bit systems. |
| 20 return *offset <= std::numeric_limits<uint32_t>::max() && | 19 return *offset <= std::numeric_limits<uint32_t>::max() && |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 } | 41 } |
| 43 | 42 |
| 44 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { | 43 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { |
| 45 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 44 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 46 return false; | 45 return false; |
| 47 } | 46 } |
| 48 | 47 |
| 49 return true; | 48 return true; |
| 50 } | 49 } |
| 51 | 50 |
| 52 bool ValidateMessageIsRequestWithoutResponse(const Message* message) { | |
| 53 if (message->has_flag(kMessageIsResponse) || | |
| 54 message->has_flag(kMessageExpectsResponse)) { | |
| 55 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS); | |
| 56 return false; | |
| 57 } | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 bool ValidateMessageIsRequestExpectingResponse(const Message* message) { | |
| 62 if (message->has_flag(kMessageIsResponse) || | |
| 63 !message->has_flag(kMessageExpectsResponse)) { | |
| 64 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS); | |
| 65 return false; | |
| 66 } | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 bool ValidateMessageIsResponse(const Message* message) { | |
| 71 if (message->has_flag(kMessageExpectsResponse) || | |
| 72 !message->has_flag(kMessageIsResponse)) { | |
| 73 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS); | |
| 74 return false; | |
| 75 } | |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 } // namespace internal | 51 } // namespace internal |
| 80 } // namespace mojo | 52 } // namespace mojo |
| OLD | NEW |