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_VALIDATION_UTIL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | 10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" |
11 #include "mojo/public/cpp/bindings/message.h" | 11 #include "mojo/public/cpp/bindings/message.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 // Checks whether decoding the pointer will overflow and produce a pointer | 16 // Checks whether decoding the pointer will overflow and produce a pointer |
17 // smaller than |offset|. | 17 // smaller than |offset|. |
18 bool ValidateEncodedPointer(const uint64_t* offset); | 18 bool ValidateEncodedPointer(const uint64_t* offset); |
19 | 19 |
20 // Validates that |data| contains a valid struct header, in terms of alignment | 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 | 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 | 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 | 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. | 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 | 25 // Note: Does not verify |version| or that |num_bytes| is correct for the |
26 // claimed version. | 26 // claimed version. |
27 bool ValidateStructHeaderAndClaimMemory(const void* data, | 27 bool ValidateStructHeaderAndClaimMemory(const void* data, |
28 BoundsChecker* bounds_checker); | 28 BoundsChecker* bounds_checker); |
29 | 29 |
30 // TODO(vardhan): Move the following |Message| related functions (mostly just | |
viettrungluu
2015/10/19 19:37:54
Could you do that first?
vardhan
2015/10/19 23:18:31
Done.
| |
31 // the templated ones) out of here so this header does not need to depend on | |
32 // message.h. | |
33 | |
30 // Validates that the message is a request which doesn't expect a response. | 34 // Validates that the message is a request which doesn't expect a response. |
31 bool ValidateMessageIsRequestWithoutResponse(const Message* message); | 35 bool ValidateMessageIsRequestWithoutResponse(const Message* message); |
32 // Validates that the message is a request expecting a response. | 36 // Validates that the message is a request expecting a response. |
33 bool ValidateMessageIsRequestExpectingResponse(const Message* message); | 37 bool ValidateMessageIsRequestExpectingResponse(const Message* message); |
34 // Validates that the message is a response. | 38 // Validates that the message is a response. |
35 bool ValidateMessageIsResponse(const Message* message); | 39 bool ValidateMessageIsResponse(const Message* message); |
36 | 40 |
37 // Validates that the message payload is a valid struct of type ParamsType. | 41 // Validates that the message payload is a valid struct of type ParamsType. |
38 template <typename ParamsType> | 42 template <typename ParamsType> |
39 bool ValidateMessagePayload(const Message* message) { | 43 bool ValidateMessagePayload(const Message* message) { |
40 BoundsChecker bounds_checker(message->payload(), message->payload_num_bytes(), | 44 BoundsChecker bounds_checker(message->payload(), message->payload_num_bytes(), |
41 message->handles()->size()); | 45 message->handles()->size()); |
42 return ParamsType::Validate(message->payload(), &bounds_checker); | 46 return ParamsType::Validate(message->payload(), &bounds_checker); |
43 } | 47 } |
44 | 48 |
45 } // namespace internal | 49 } // namespace internal |
46 } // namespace mojo | 50 } // namespace mojo |
47 | 51 |
48 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 52 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ |
OLD | NEW |