| 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 11 #include "mojo/public/cpp/bindings/lib/serialization_util.h" | 11 #include "mojo/public/cpp/bindings/lib/serialization_util.h" |
| 12 #include "mojo/public/cpp/bindings/lib/validate_params.h" | 12 #include "mojo/public/cpp/bindings/lib/validate_params.h" |
| 13 #include "mojo/public/cpp/bindings/lib/validation_context.h" | 13 #include "mojo/public/cpp/bindings/lib/validation_context.h" |
| 14 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 14 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| 15 #include "mojo/public/cpp/bindings/message.h" | 15 #include "mojo/public/cpp/bindings/message.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace internal { | 18 namespace internal { |
| 19 | 19 |
| 20 // Checks whether decoding the pointer will overflow and produce a pointer | 20 // Checks whether decoding the pointer will overflow and produce a pointer |
| 21 // smaller than |offset|. | 21 // smaller than |offset|. |
| 22 bool ValidateEncodedPointer(const uint64_t* offset); | 22 inline bool ValidateEncodedPointer(const uint64_t* offset) { |
| 23 // - Make sure |*offset| is no more than 32-bits. |
| 24 // - Cast |offset| to uintptr_t so overflow behavior is well defined across |
| 25 // 32-bit and 64-bit systems. |
| 26 return *offset <= std::numeric_limits<uint32_t>::max() && |
| 27 (reinterpret_cast<uintptr_t>(offset) + |
| 28 static_cast<uint32_t>(*offset) >= |
| 29 reinterpret_cast<uintptr_t>(offset)); |
| 30 } |
| 23 | 31 |
| 24 template <typename T> | 32 template <typename T> |
| 25 bool ValidatePointer(const Pointer<T>& input, | 33 bool ValidatePointer(const Pointer<T>& input, |
| 26 ValidationContext* validation_context) { | 34 ValidationContext* validation_context) { |
| 27 bool result = ValidateEncodedPointer(&input.offset); | 35 bool result = ValidateEncodedPointer(&input.offset); |
| 28 if (!result) | 36 if (!result) |
| 29 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER); | 37 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER); |
| 30 | 38 |
| 31 return result; | 39 return result; |
| 32 } | 40 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 ValidationContext* validation_context); | 169 ValidationContext* validation_context); |
| 162 bool ValidateHandleOrInterface(const Interface_Data& input, | 170 bool ValidateHandleOrInterface(const Interface_Data& input, |
| 163 ValidationContext* validation_context); | 171 ValidationContext* validation_context); |
| 164 bool ValidateHandleOrInterface(const Handle_Data& input, | 172 bool ValidateHandleOrInterface(const Handle_Data& input, |
| 165 ValidationContext* validation_context); | 173 ValidationContext* validation_context); |
| 166 | 174 |
| 167 } // namespace internal | 175 } // namespace internal |
| 168 } // namespace mojo | 176 } // namespace mojo |
| 169 | 177 |
| 170 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 178 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ |
| OLD | NEW |