| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bindings_serialization.h" | 5 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | 10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" |
| 11 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace mojo { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const size_t kAlignment = 8; | 18 const size_t kAlignment = 8; |
| 18 | 19 |
| 19 template<typename T> | 20 template<typename T> |
| 20 T AlignImpl(T t) { | 21 T AlignImpl(T t) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 77 } |
| 77 assert(handle->value() < handles->size()); | 78 assert(handle->value() < handles->size()); |
| 78 // Just leave holes in the vector so we don't screw up other indices. | 79 // Just leave holes in the vector so we don't screw up other indices. |
| 79 *handle = FetchAndReset(&handles->at(handle->value())); | 80 *handle = FetchAndReset(&handles->at(handle->value())); |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool ValidateStructHeader(const void* data, | 83 bool ValidateStructHeader(const void* data, |
| 83 uint32_t min_num_bytes, | 84 uint32_t min_num_bytes, |
| 84 uint32_t min_num_fields, | 85 uint32_t min_num_fields, |
| 85 BoundsChecker* bounds_checker) { | 86 BoundsChecker* bounds_checker) { |
| 86 if (!IsAligned(data)) | 87 if (!IsAligned(data)) { |
| 88 ReportValidationError(VALIDATION_ERROR_MISALIGNED_OBJECT); |
| 87 return false; | 89 return false; |
| 88 if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) | 90 } |
| 91 if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) { |
| 92 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 89 return false; | 93 return false; |
| 94 } |
| 90 | 95 |
| 91 const StructHeader* header = static_cast<const StructHeader*>(data); | 96 const StructHeader* header = static_cast<const StructHeader*>(data); |
| 92 | 97 |
| 93 // TODO(yzshen): Currently our binding code cannot handle structs of smaller | 98 // TODO(yzshen): Currently our binding code cannot handle structs of smaller |
| 94 // size or with fewer fields than the version that it sees. That needs to be | 99 // size or with fewer fields than the version that it sees. That needs to be |
| 95 // changed in order to provide backward compatibility. | 100 // changed in order to provide backward compatibility. |
| 96 if (header->num_bytes < min_num_bytes || header->num_fields < min_num_fields) | 101 if (header->num_bytes < min_num_bytes || |
| 102 header->num_fields < min_num_fields) { |
| 103 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER); |
| 97 return false; | 104 return false; |
| 105 } |
| 98 | 106 |
| 99 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) | 107 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { |
| 108 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 100 return false; | 109 return false; |
| 110 } |
| 101 | 111 |
| 102 return true; | 112 return true; |
| 103 } | 113 } |
| 104 | 114 |
| 105 } // namespace internal | 115 } // namespace internal |
| 106 } // namespace mojo | 116 } // namespace mojo |
| OLD | NEW |