| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "mojo/public/cpp/bindings/lib/message_internal.h" | 11 #include "mojo/public/cpp/bindings/lib/message_internal.h" |
| 12 #include "mojo/public/cpp/bindings/lib/serialization_util.h" | 12 #include "mojo/public/cpp/bindings/lib/serialization_util.h" |
| 13 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 13 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| 14 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h" | 14 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 bool ValidateEncodedPointer(const uint64_t* offset) { | |
| 20 // - Make sure |*offset| is no more than 32-bits. | |
| 21 // - Cast |offset| to uintptr_t so overflow behavior is well defined across | |
| 22 // 32-bit and 64-bit systems. | |
| 23 return *offset <= std::numeric_limits<uint32_t>::max() && | |
| 24 (reinterpret_cast<uintptr_t>(offset) + | |
| 25 static_cast<uint32_t>(*offset) >= | |
| 26 reinterpret_cast<uintptr_t>(offset)); | |
| 27 } | |
| 28 | |
| 29 bool ValidateStructHeaderAndClaimMemory(const void* data, | 19 bool ValidateStructHeaderAndClaimMemory(const void* data, |
| 30 ValidationContext* validation_context) { | 20 ValidationContext* validation_context) { |
| 31 if (!IsAligned(data)) { | 21 if (!IsAligned(data)) { |
| 32 ReportValidationError(validation_context, | 22 ReportValidationError(validation_context, |
| 33 VALIDATION_ERROR_MISALIGNED_OBJECT); | 23 VALIDATION_ERROR_MISALIGNED_OBJECT); |
| 34 return false; | 24 return false; |
| 35 } | 25 } |
| 36 if (!validation_context->IsValidRange(data, sizeof(StructHeader))) { | 26 if (!validation_context->IsValidRange(data, sizeof(StructHeader))) { |
| 37 ReportValidationError(validation_context, | 27 ReportValidationError(validation_context, |
| 38 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 28 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ValidationContext* validation_context) { | 233 ValidationContext* validation_context) { |
| 244 if (validation_context->ClaimHandle(input)) | 234 if (validation_context->ClaimHandle(input)) |
| 245 return true; | 235 return true; |
| 246 | 236 |
| 247 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE); | 237 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE); |
| 248 return false; | 238 return false; |
| 249 } | 239 } |
| 250 | 240 |
| 251 } // namespace internal | 241 } // namespace internal |
| 252 } // namespace mojo | 242 } // namespace mojo |
| OLD | NEW |