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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_VALIDATION_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_VALIDATION_H_ |
7 | |
8 #include <stdint.h> | |
9 | 7 |
10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | 8 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" |
11 #include "mojo/public/cpp/bindings/message.h" | 9 #include "mojo/public/cpp/bindings/message.h" |
12 | 10 |
13 namespace mojo { | 11 namespace mojo { |
14 namespace internal { | 12 namespace internal { |
15 | 13 |
16 // Checks whether decoding the pointer will overflow and produce a pointer | |
17 // smaller than |offset|. | |
18 bool ValidateEncodedPointer(const uint64_t* offset); | |
19 | |
20 // Validates that |data| contains a valid struct header, in terms of alignment | |
21 // and size (i.e., the |num_bytes| field of the header is sufficient for storing | |
22 // the header itself). Besides, it checks that the memory range | |
23 // [data, data + num_bytes) is not marked as occupied by other objects in | |
24 // |bounds_checker|. On success, the memory range is marked as occupied. | |
25 // Note: Does not verify |version| or that |num_bytes| is correct for the | |
26 // claimed version. | |
27 bool ValidateStructHeaderAndClaimMemory(const void* data, | |
28 BoundsChecker* bounds_checker); | |
29 | |
30 // Validates that the message is a request which doesn't expect a response. | 14 // Validates that the message is a request which doesn't expect a response. |
31 bool ValidateMessageIsRequestWithoutResponse(const Message* message); | 15 bool ValidateMessageIsRequestWithoutResponse(const Message* message); |
32 // Validates that the message is a request expecting a response. | 16 // Validates that the message is a request expecting a response. |
33 bool ValidateMessageIsRequestExpectingResponse(const Message* message); | 17 bool ValidateMessageIsRequestExpectingResponse(const Message* message); |
34 // Validates that the message is a response. | 18 // Validates that the message is a response. |
35 bool ValidateMessageIsResponse(const Message* message); | 19 bool ValidateMessageIsResponse(const Message* message); |
36 | 20 |
37 // Validates that the message payload is a valid struct of type ParamsType. | 21 // Validates that the message payload is a valid struct of type ParamsType. |
38 template <typename ParamsType> | 22 template <typename ParamsType> |
39 bool ValidateMessagePayload(const Message* message) { | 23 bool ValidateMessagePayload(const Message* message) { |
40 BoundsChecker bounds_checker(message->payload(), message->payload_num_bytes(), | 24 BoundsChecker bounds_checker(message->payload(), message->payload_num_bytes(), |
41 message->handles()->size()); | 25 message->handles()->size()); |
42 return ParamsType::Validate(message->payload(), &bounds_checker); | 26 return ParamsType::Validate(message->payload(), &bounds_checker); |
43 } | 27 } |
44 | 28 |
45 } // namespace internal | 29 } // namespace internal |
46 } // namespace mojo | 30 } // namespace mojo |
47 | 31 |
48 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 32 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_VALIDATION_H_ |
OLD | NEW |