Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_util.h

Issue 2312813002: Limit Mojo messages recursion depth (Closed)
Patch Set: Address review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bindings_internal.h" 10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 ValidationContext* validation_context); 125 ValidationContext* validation_context);
126 bool ValidateHandleOrInterfaceNonNullable( 126 bool ValidateHandleOrInterfaceNonNullable(
127 const Handle_Data& input, 127 const Handle_Data& input,
128 const char* error_message, 128 const char* error_message,
129 ValidationContext* validation_context); 129 ValidationContext* validation_context);
130 130
131 template <typename T> 131 template <typename T>
132 bool ValidateContainer(const Pointer<T>& input, 132 bool ValidateContainer(const Pointer<T>& input,
133 ValidationContext* validation_context, 133 ValidationContext* validation_context,
134 const ContainerValidateParams* validate_params) { 134 const ContainerValidateParams* validate_params) {
135 ValidationContext::ScopedDepthTracker depth_tracker(validation_context);
136 if (validation_context->ExceedsMaxDepth()) {
137 ReportValidationError(validation_context,
138 VALIDATION_ERROR_MAX_RECURSION_DEPTH);
139 return false;
140 }
135 return ValidatePointer(input, validation_context) && 141 return ValidatePointer(input, validation_context) &&
136 T::Validate(input.Get(), validation_context, validate_params); 142 T::Validate(input.Get(), validation_context, validate_params);
137 } 143 }
138 144
139 template <typename T> 145 template <typename T>
140 bool ValidateStruct(const Pointer<T>& input, 146 bool ValidateStruct(const Pointer<T>& input,
141 ValidationContext* validation_context) { 147 ValidationContext* validation_context) {
148 ValidationContext::ScopedDepthTracker depth_tracker(validation_context);
149 if (validation_context->ExceedsMaxDepth()) {
150 ReportValidationError(validation_context,
151 VALIDATION_ERROR_MAX_RECURSION_DEPTH);
152 return false;
153 }
142 return ValidatePointer(input, validation_context) && 154 return ValidatePointer(input, validation_context) &&
143 T::Validate(input.Get(), validation_context); 155 T::Validate(input.Get(), validation_context);
144 } 156 }
145 157
146 template <typename T> 158 template <typename T>
147 bool ValidateInlinedUnion(const T& input, 159 bool ValidateInlinedUnion(const T& input,
148 ValidationContext* validation_context) { 160 ValidationContext* validation_context) {
161 ValidationContext::ScopedDepthTracker depth_tracker(validation_context);
162 if (validation_context->ExceedsMaxDepth()) {
163 ReportValidationError(validation_context,
164 VALIDATION_ERROR_MAX_RECURSION_DEPTH);
165 return false;
166 }
149 return T::Validate(&input, validation_context, true); 167 return T::Validate(&input, validation_context, true);
150 } 168 }
151 169
152 template <typename T> 170 template <typename T>
153 bool ValidateNonInlinedUnion(const Pointer<T>& input, 171 bool ValidateNonInlinedUnion(const Pointer<T>& input,
154 ValidationContext* validation_context) { 172 ValidationContext* validation_context) {
173 ValidationContext::ScopedDepthTracker depth_tracker(validation_context);
174 if (validation_context->ExceedsMaxDepth()) {
175 ReportValidationError(validation_context,
176 VALIDATION_ERROR_MAX_RECURSION_DEPTH);
177 return false;
178 }
155 return ValidatePointer(input, validation_context) && 179 return ValidatePointer(input, validation_context) &&
156 T::Validate(input.Get(), validation_context, false); 180 T::Validate(input.Get(), validation_context, false);
157 } 181 }
158 182
159 bool ValidateHandleOrInterface(const AssociatedInterface_Data& input, 183 bool ValidateHandleOrInterface(const AssociatedInterface_Data& input,
160 ValidationContext* validation_context); 184 ValidationContext* validation_context);
161 bool ValidateHandleOrInterface(const AssociatedInterfaceRequest_Data& input, 185 bool ValidateHandleOrInterface(const AssociatedInterfaceRequest_Data& input,
162 ValidationContext* validation_context); 186 ValidationContext* validation_context);
163 bool ValidateHandleOrInterface(const Interface_Data& input, 187 bool ValidateHandleOrInterface(const Interface_Data& input,
164 ValidationContext* validation_context); 188 ValidationContext* validation_context);
165 bool ValidateHandleOrInterface(const Handle_Data& input, 189 bool ValidateHandleOrInterface(const Handle_Data& input,
166 ValidationContext* validation_context); 190 ValidationContext* validation_context);
167 191
168 } // namespace internal 192 } // namespace internal
169 } // namespace mojo 193 } // namespace mojo
170 194
171 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ 195 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698