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" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 assert(handle->value() < handles->size()); | 78 assert(handle->value() < handles->size()); |
79 // 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. |
80 *handle = FetchAndReset(&handles->at(handle->value())); | 80 *handle = FetchAndReset(&handles->at(handle->value())); |
81 } | 81 } |
82 | 82 |
83 bool ValidateStructHeader(const void* data, | 83 bool ValidateStructHeader(const void* data, |
84 uint32_t min_num_bytes, | 84 uint32_t min_num_bytes, |
85 uint32_t min_num_fields, | 85 uint32_t min_num_fields, |
86 BoundsChecker* bounds_checker) { | 86 BoundsChecker* bounds_checker) { |
| 87 assert(min_num_bytes >= sizeof(StructHeader)); |
| 88 |
87 if (!IsAligned(data)) { | 89 if (!IsAligned(data)) { |
88 ReportValidationError(VALIDATION_ERROR_MISALIGNED_OBJECT); | 90 ReportValidationError(VALIDATION_ERROR_MISALIGNED_OBJECT); |
89 return false; | 91 return false; |
90 } | 92 } |
91 if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) { | 93 if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) { |
92 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 94 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
93 return false; | 95 return false; |
94 } | 96 } |
95 | 97 |
96 const StructHeader* header = static_cast<const StructHeader*>(data); | 98 const StructHeader* header = static_cast<const StructHeader*>(data); |
(...skipping 10 matching lines...) Expand all Loading... |
107 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { | 109 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { |
108 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 110 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
109 return false; | 111 return false; |
110 } | 112 } |
111 | 113 |
112 return true; | 114 return true; |
113 } | 115 } |
114 | 116 |
115 } // namespace internal | 117 } // namespace internal |
116 } // namespace mojo | 118 } // namespace mojo |
OLD | NEW |