| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 if (!validation_context->ClaimMemory(data, header->num_bytes)) { | 40 if (!validation_context->ClaimMemory(data, header->num_bytes)) { |
| 41 ReportValidationError(validation_context, | 41 ReportValidationError(validation_context, |
| 42 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 42 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 | 45 |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool ValidateUnionHeaderAndClaimMemory(const void* data, | 49 bool ValidateNonInlinedUnionHeaderAndClaimMemory( |
| 50 bool inlined, | 50 const void* data, |
| 51 ValidationContext* validation_context) { | 51 ValidationContext* validation_context) { |
| 52 if (!IsAligned(data)) { | 52 if (!IsAligned(data)) { |
| 53 ReportValidationError(validation_context, | 53 ReportValidationError(validation_context, |
| 54 VALIDATION_ERROR_MISALIGNED_OBJECT); | 54 VALIDATION_ERROR_MISALIGNED_OBJECT); |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // If the union is inlined in another structure its memory was already | 58 if (!validation_context->ClaimMemory(data, kUnionDataSize) || |
| 59 // claimed. | 59 *static_cast<const uint32_t*>(data) != kUnionDataSize) { |
| 60 // This ONLY applies to the union itself, NOT anything which the union points | |
| 61 // to. | |
| 62 if (!inlined && !validation_context->ClaimMemory(data, kUnionDataSize)) { | |
| 63 ReportValidationError(validation_context, | 60 ReportValidationError(validation_context, |
| 64 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 61 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 65 return false; | 62 return false; |
| 66 } | 63 } |
| 67 | 64 |
| 68 return true; | 65 return true; |
| 69 } | 66 } |
| 70 | 67 |
| 71 bool ValidateMessageIsRequestWithoutResponse( | 68 bool ValidateMessageIsRequestWithoutResponse( |
| 72 const Message* message, | 69 const Message* message, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 ValidationContext* validation_context) { | 230 ValidationContext* validation_context) { |
| 234 if (validation_context->ClaimHandle(input)) | 231 if (validation_context->ClaimHandle(input)) |
| 235 return true; | 232 return true; |
| 236 | 233 |
| 237 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE); | 234 ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE); |
| 238 return false; | 235 return false; |
| 239 } | 236 } |
| 240 | 237 |
| 241 } // namespace internal | 238 } // namespace internal |
| 242 } // namespace mojo | 239 } // namespace mojo |
| OLD | NEW |