OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/c/bindings/message.h" | 5 #include <mojo/bindings/message.h> |
6 | 6 |
| 7 #include <mojo/bindings/struct.h> |
7 #include <stdint.h> | 8 #include <stdint.h> |
8 | 9 |
9 #include "mojo/public/c/bindings/struct.h" | |
10 | |
11 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf, | 10 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf, |
12 uint32_t in_buf_size) { | 11 uint32_t in_buf_size) { |
13 const struct MojomStructHeader* header = | 12 const struct MojomStructHeader* header = |
14 (const struct MojomStructHeader*)in_buf; | 13 (const struct MojomStructHeader*)in_buf; |
15 | 14 |
16 if (in_buf_size < sizeof(struct MojomStructHeader) || | 15 if (in_buf_size < sizeof(struct MojomStructHeader) || |
17 in_buf_size < header->num_bytes) | 16 in_buf_size < header->num_bytes) |
18 return MOJOM_VALIDATION_ILLEGAL_MEMORY_RANGE; | 17 return MOJOM_VALIDATION_ILLEGAL_MEMORY_RANGE; |
19 | 18 |
20 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; | 19 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; |
21 if (header->version == 0u) { | 20 if (header->version == 0u) { |
22 if (header->num_bytes != sizeof(struct MojomMessage)) { | 21 if (header->num_bytes != sizeof(struct MojomMessage)) { |
23 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER; | 22 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER; |
24 } | 23 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; | 64 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; |
66 } | 65 } |
67 | 66 |
68 MojomValidationResult MojomMessage_ValidateResponse( | 67 MojomValidationResult MojomMessage_ValidateResponse( |
69 const void* in_buf) { | 68 const void* in_buf) { |
70 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; | 69 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; |
71 return (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE) | 70 return (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE) |
72 ? MOJOM_VALIDATION_ERROR_NONE | 71 ? MOJOM_VALIDATION_ERROR_NONE |
73 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; | 72 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; |
74 } | 73 } |
OLD | NEW |