Chromium Code Reviews| 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/public/c/bindings/message.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "mojo/public/c/bindings/struct.h" | 9 #include "mojo/public/c/bindings/struct.h" |
| 10 | 10 |
| 11 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf, | 11 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf, |
| 12 uint32_t in_buf_size) { | 12 uint32_t in_buf_size) { |
| 13 const struct MojomStructHeader* header = | 13 const struct MojomStructHeader* header = |
| 14 (const struct MojomStructHeader*)in_buf; | 14 (const struct MojomStructHeader*)in_buf; |
| 15 | |
| 15 if (in_buf_size < sizeof(struct MojomStructHeader) || | 16 if (in_buf_size < sizeof(struct MojomStructHeader) || |
|
viettrungluu
2016/07/28 23:03:01
For arrays, you return "illegal memory range" for
vardhan
2016/07/29 21:29:21
True -- this should be split up (but i guess the v
| |
| 16 in_buf_size < header->num_bytes) { | 17 in_buf_size < header->num_bytes) |
| 17 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER; | 18 return MOJOM_VALIDATION_ILLEGAL_MEMORY_RANGE; |
| 18 } | |
| 19 | 19 |
| 20 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; | 20 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; |
| 21 if (header->version == 0u) { | 21 if (header->version == 0u) { |
| 22 if (header->num_bytes != sizeof(struct MojomMessage)) { | 22 if (header->num_bytes != sizeof(struct MojomMessage)) { |
| 23 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER; | 23 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Version 0 has no request id and should not have either of these flags. | 26 // Version 0 has no request id and should not have either of these flags. |
| 27 if ((msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) || | 27 if ((msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) || |
| 28 (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)) { | 28 (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 // Mutually exclusive flags. | 41 // Mutually exclusive flags. |
| 42 if ((msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) && | 42 if ((msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) && |
| 43 (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)) { | 43 (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)) { |
| 44 return MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; | 44 return MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Accept unknown versions of the message header to be future-proof. | 47 // Accept unknown versions of the message header to be future-proof. |
| 48 return MOJOM_VALIDATION_ERROR_NONE; | 48 return MOJOM_VALIDATION_ERROR_NONE; |
| 49 } | 49 } |
| 50 | |
| 51 MojomValidationResult MojomMessage_ValidateRequestExpectingResponse( | |
| 52 const void* in_buf) { | |
| 53 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; | |
| 54 return (msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) | |
| 55 ? MOJOM_VALIDATION_ERROR_NONE | |
| 56 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; | |
| 57 } | |
| 58 | |
| 59 MojomValidationResult MojomMessage_ValidateRequestWithoutResponse( | |
| 60 const void* in_buf) { | |
| 61 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; | |
| 62 return !(msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) && | |
|
viettrungluu
2016/07/28 23:03:01
nit: I'd suggest always putting (...) around the e
vardhan
2016/07/29 21:29:21
Done.
| |
| 63 !(msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE) | |
| 64 ? MOJOM_VALIDATION_ERROR_NONE | |
| 65 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; | |
| 66 } | |
| 67 | |
| 68 MojomValidationResult MojomMessage_ValidateResponse( | |
| 69 const void* in_buf) { | |
| 70 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf; | |
| 71 return msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE | |
|
viettrungluu
2016/07/28 23:03:01
"
vardhan
2016/07/29 21:29:21
Done.
| |
| 72 ? MOJOM_VALIDATION_ERROR_NONE | |
| 73 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS; | |
| 74 } | |
| OLD | NEW |