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

Unified Diff: mojo/public/cpp/bindings/lib/validation_util.h

Issue 1486573003: Mojo C++ bindings: associated interface pointers/requests validation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.cc ('k') | mojo/public/cpp/bindings/lib/validation_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/validation_util.h
diff --git a/mojo/public/cpp/bindings/lib/validation_util.h b/mojo/public/cpp/bindings/lib/validation_util.h
index 6853f457ef1584fbec70c540381d5099248340b7..41049c03c9880168d6755ad4d6311dae0fe8fa88 100644
--- a/mojo/public/cpp/bindings/lib/validation_util.h
+++ b/mojo/public/cpp/bindings/lib/validation_util.h
@@ -7,7 +7,10 @@
#include <stdint.h>
+#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
+#include "mojo/public/cpp/bindings/lib/validate_params.h"
+#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/message.h"
namespace mojo {
@@ -47,6 +50,80 @@ bool ValidateMessagePayload(const Message* message) {
bool ValidateControlRequest(const Message* message);
bool ValidateControlResponse(const Message* message);
+// The following Validate.*NonNullable() functions validate that the given
+// |input| is not null/invalid.
+template <typename T>
+bool ValidatePointerNonNullable(const T& input, const char* error_message) {
+ if (input.offset)
+ return true;
+
+ ReportValidationError(VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
+ error_message);
+ return false;
+}
+
+template <typename T>
+bool ValidateInlinedUnionNonNullable(const T& input,
+ const char* error_message) {
+ if (!input.is_null())
+ return true;
+
+ ReportValidationError(VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
+ error_message);
+ return false;
+}
+
+bool ValidateHandleNonNullable(const Handle& input, const char* error_message);
+
+bool ValidateInterfaceIdNonNullable(InterfaceId input,
+ const char* error_message);
+
+template <typename T>
+bool ValidateArray(const ArrayPointer<T>& input,
+ BoundsChecker* bounds_checker,
+ const ArrayValidateParams* validate_params) {
+ if (!ValidateEncodedPointer(&input.offset)) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER);
+ return false;
+ }
+
+ return Array_Data<T>::Validate(DecodePointerRaw(&input.offset),
+ bounds_checker, validate_params);
+}
+
+template <typename T>
+bool ValidateMap(const StructPointer<T>& input,
+ BoundsChecker* bounds_checker,
+ const ArrayValidateParams* value_validate_params) {
+ if (!ValidateEncodedPointer(&input.offset)) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER);
+ return false;
+ }
+
+ return T::Validate(DecodePointerRaw(&input.offset), bounds_checker,
+ value_validate_params);
+}
+
+template <typename T>
+bool ValidateStruct(const StructPointer<T>& input,
+ BoundsChecker* bounds_checker) {
+ if (!ValidateEncodedPointer(&input.offset)) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER);
+ return false;
+ }
+
+ return T::Validate(DecodePointerRaw(&input.offset), bounds_checker);
+}
+
+template <typename T>
+bool ValidateInlinedUnion(const T& input, BoundsChecker* bounds_checker) {
+ return T::Validate(&input, bounds_checker, true);
+}
+
+bool ValidateHandle(const Handle& input, BoundsChecker* bounds_checker);
+
+bool ValidateAssociatedInterfaceId(InterfaceId input);
+
} // namespace internal
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.cc ('k') | mojo/public/cpp/bindings/lib/validation_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698