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/bindings_export.h" | |
10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 11 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
11 #include "mojo/public/cpp/bindings/lib/serialization_util.h" | 12 #include "mojo/public/cpp/bindings/lib/serialization_util.h" |
12 #include "mojo/public/cpp/bindings/lib/validate_params.h" | 13 #include "mojo/public/cpp/bindings/lib/validate_params.h" |
13 #include "mojo/public/cpp/bindings/lib/validation_context.h" | 14 #include "mojo/public/cpp/bindings/lib/validation_context.h" |
14 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 15 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
15 #include "mojo/public/cpp/bindings/message.h" | 16 #include "mojo/public/cpp/bindings/message.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 namespace internal { | 19 namespace internal { |
19 | 20 |
(...skipping 19 matching lines...) Expand all Loading... | |
39 return result; | 40 return result; |
40 } | 41 } |
41 | 42 |
42 // Validates that |data| contains a valid struct header, in terms of alignment | 43 // Validates that |data| contains a valid struct header, in terms of alignment |
43 // and size (i.e., the |num_bytes| field of the header is sufficient for storing | 44 // and size (i.e., the |num_bytes| field of the header is sufficient for storing |
44 // the header itself). Besides, it checks that the memory range | 45 // the header itself). Besides, it checks that the memory range |
45 // [data, data + num_bytes) is not marked as occupied by other objects in | 46 // [data, data + num_bytes) is not marked as occupied by other objects in |
46 // |validation_context|. On success, the memory range is marked as occupied. | 47 // |validation_context|. On success, the memory range is marked as occupied. |
47 // Note: Does not verify |version| or that |num_bytes| is correct for the | 48 // Note: Does not verify |version| or that |num_bytes| is correct for the |
48 // claimed version. | 49 // claimed version. |
49 bool ValidateStructHeaderAndClaimMemory(const void* data, | 50 MOJO_CPP_BINDINGS_EXPORT bool ValidateStructHeaderAndClaimMemory( |
yzshen1
2016/09/22 18:26:27
I notice that some places put MOJO_CPP_BINDINGS_EX
dcheng
2016/09/22 22:18:21
I thought I fixed them all but I guessed I missed
| |
50 ValidationContext* validation_context); | 51 const void* data, |
52 ValidationContext* validation_context); | |
51 | 53 |
52 // Validates that |data| contains a valid union header, in terms of alignment | 54 // Validates that |data| contains a valid union header, in terms of alignment |
53 // and size. It checks that the memory range [data, data + kUnionDataSize) is | 55 // and size. It checks that the memory range [data, data + kUnionDataSize) is |
54 // not marked as occupied by other objects in |validation_context|. On success, | 56 // not marked as occupied by other objects in |validation_context|. On success, |
55 // the memory range is marked as occupied. | 57 // the memory range is marked as occupied. |
56 bool ValidateNonInlinedUnionHeaderAndClaimMemory( | 58 MOJO_CPP_BINDINGS_EXPORT bool ValidateNonInlinedUnionHeaderAndClaimMemory( |
57 const void* data, | 59 const void* data, |
58 ValidationContext* validation_context); | 60 ValidationContext* validation_context); |
59 | 61 |
60 // Validates that the message is a request which doesn't expect a response. | 62 // Validates that the message is a request which doesn't expect a response. |
61 bool ValidateMessageIsRequestWithoutResponse( | 63 MOJO_CPP_BINDINGS_EXPORT bool ValidateMessageIsRequestWithoutResponse( |
62 const Message* message, | 64 const Message* message, |
63 ValidationContext* validation_context); | 65 ValidationContext* validation_context); |
64 | 66 |
65 // Validates that the message is a request expecting a response. | 67 // Validates that the message is a request expecting a response. |
66 bool ValidateMessageIsRequestExpectingResponse( | 68 MOJO_CPP_BINDINGS_EXPORT bool ValidateMessageIsRequestExpectingResponse( |
67 const Message* message, | 69 const Message* message, |
68 ValidationContext* validation_context); | 70 ValidationContext* validation_context); |
69 | 71 |
70 // Validates that the message is a response. | 72 // Validates that the message is a response. |
71 bool ValidateMessageIsResponse(const Message* message, | 73 MOJO_CPP_BINDINGS_EXPORT bool ValidateMessageIsResponse( |
72 ValidationContext* validation_context); | 74 const Message* message, |
75 ValidationContext* validation_context); | |
73 | 76 |
74 // Validates that the message payload is a valid struct of type ParamsType. | 77 // Validates that the message payload is a valid struct of type ParamsType. |
75 template <typename ParamsType> | 78 template <typename ParamsType> |
76 bool ValidateMessagePayload(const Message* message, | 79 bool ValidateMessagePayload(const Message* message, |
77 ValidationContext* validation_context) { | 80 ValidationContext* validation_context) { |
78 return ParamsType::Validate(message->payload(), validation_context); | 81 return ParamsType::Validate(message->payload(), validation_context); |
79 } | 82 } |
80 | 83 |
81 // The following Validate.*NonNullable() functions validate that the given | 84 // The following Validate.*NonNullable() functions validate that the given |
82 // |input| is not null/invalid. | 85 // |input| is not null/invalid. |
(...skipping 16 matching lines...) Expand all Loading... | |
99 ValidationContext* validation_context) { | 102 ValidationContext* validation_context) { |
100 if (!input.is_null()) | 103 if (!input.is_null()) |
101 return true; | 104 return true; |
102 | 105 |
103 ReportValidationError(validation_context, | 106 ReportValidationError(validation_context, |
104 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 107 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
105 error_message); | 108 error_message); |
106 return false; | 109 return false; |
107 } | 110 } |
108 | 111 |
109 bool IsHandleOrInterfaceValid(const AssociatedInterface_Data& input); | 112 MOJO_CPP_BINDINGS_EXPORT bool IsHandleOrInterfaceValid( |
110 bool IsHandleOrInterfaceValid(const AssociatedInterfaceRequest_Data& input); | 113 const AssociatedInterface_Data& input); |
111 bool IsHandleOrInterfaceValid(const Interface_Data& input); | 114 MOJO_CPP_BINDINGS_EXPORT bool IsHandleOrInterfaceValid( |
112 bool IsHandleOrInterfaceValid(const Handle_Data& input); | 115 const AssociatedInterfaceRequest_Data& input); |
116 MOJO_CPP_BINDINGS_EXPORT bool IsHandleOrInterfaceValid( | |
117 const Interface_Data& input); | |
118 MOJO_CPP_BINDINGS_EXPORT bool IsHandleOrInterfaceValid( | |
119 const Handle_Data& input); | |
113 | 120 |
114 bool ValidateHandleOrInterfaceNonNullable( | 121 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterfaceNonNullable( |
115 const AssociatedInterface_Data& input, | 122 const AssociatedInterface_Data& input, |
116 const char* error_message, | 123 const char* error_message, |
117 ValidationContext* validation_context); | 124 ValidationContext* validation_context); |
118 bool ValidateHandleOrInterfaceNonNullable( | 125 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterfaceNonNullable( |
119 const AssociatedInterfaceRequest_Data& input, | 126 const AssociatedInterfaceRequest_Data& input, |
120 const char* error_message, | 127 const char* error_message, |
121 ValidationContext* validation_context); | 128 ValidationContext* validation_context); |
122 bool ValidateHandleOrInterfaceNonNullable( | 129 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterfaceNonNullable( |
123 const Interface_Data& input, | 130 const Interface_Data& input, |
124 const char* error_message, | 131 const char* error_message, |
125 ValidationContext* validation_context); | 132 ValidationContext* validation_context); |
126 bool ValidateHandleOrInterfaceNonNullable( | 133 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterfaceNonNullable( |
127 const Handle_Data& input, | 134 const Handle_Data& input, |
128 const char* error_message, | 135 const char* error_message, |
129 ValidationContext* validation_context); | 136 ValidationContext* validation_context); |
130 | 137 |
131 template <typename T> | 138 template <typename T> |
132 bool ValidateContainer(const Pointer<T>& input, | 139 bool ValidateContainer(const Pointer<T>& input, |
133 ValidationContext* validation_context, | 140 ValidationContext* validation_context, |
134 const ContainerValidateParams* validate_params) { | 141 const ContainerValidateParams* validate_params) { |
135 ValidationContext::ScopedDepthTracker depth_tracker(validation_context); | 142 ValidationContext::ScopedDepthTracker depth_tracker(validation_context); |
136 if (validation_context->ExceedsMaxDepth()) { | 143 if (validation_context->ExceedsMaxDepth()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 ValidationContext::ScopedDepthTracker depth_tracker(validation_context); | 180 ValidationContext::ScopedDepthTracker depth_tracker(validation_context); |
174 if (validation_context->ExceedsMaxDepth()) { | 181 if (validation_context->ExceedsMaxDepth()) { |
175 ReportValidationError(validation_context, | 182 ReportValidationError(validation_context, |
176 VALIDATION_ERROR_MAX_RECURSION_DEPTH); | 183 VALIDATION_ERROR_MAX_RECURSION_DEPTH); |
177 return false; | 184 return false; |
178 } | 185 } |
179 return ValidatePointer(input, validation_context) && | 186 return ValidatePointer(input, validation_context) && |
180 T::Validate(input.Get(), validation_context, false); | 187 T::Validate(input.Get(), validation_context, false); |
181 } | 188 } |
182 | 189 |
183 bool ValidateHandleOrInterface(const AssociatedInterface_Data& input, | 190 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterface( |
184 ValidationContext* validation_context); | 191 const AssociatedInterface_Data& input, |
185 bool ValidateHandleOrInterface(const AssociatedInterfaceRequest_Data& input, | 192 ValidationContext* validation_context); |
186 ValidationContext* validation_context); | 193 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterface( |
187 bool ValidateHandleOrInterface(const Interface_Data& input, | 194 const AssociatedInterfaceRequest_Data& input, |
188 ValidationContext* validation_context); | 195 ValidationContext* validation_context); |
189 bool ValidateHandleOrInterface(const Handle_Data& input, | 196 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterface( |
190 ValidationContext* validation_context); | 197 const Interface_Data& input, |
198 ValidationContext* validation_context); | |
199 MOJO_CPP_BINDINGS_EXPORT bool ValidateHandleOrInterface( | |
200 const Handle_Data& input, | |
201 ValidationContext* validation_context); | |
191 | 202 |
192 } // namespace internal | 203 } // namespace internal |
193 } // namespace mojo | 204 } // namespace mojo |
194 | 205 |
195 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | 206 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ |
OLD | NEW |