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

Unified Diff: third_party/mojo/src/mojo/public/cpp/bindings/lib/validation_util.cc

Issue 1101303002: Update mojo sdk to rev e7270700d671fa8e458b4d8c9e47f7bcfb65da0b (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actualy provide a default TaskTracker impl Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/cpp/bindings/lib/validation_util.cc
diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/lib/validation_util.cc b/third_party/mojo/src/mojo/public/cpp/bindings/lib/validation_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5614cca4a25c9227a3d85e966c9d722bbf6e974d
--- /dev/null
+++ b/third_party/mojo/src/mojo/public/cpp/bindings/lib/validation_util.cc
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/bindings/lib/validation_util.h"
+
+#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
+#include "mojo/public/cpp/bindings/lib/message_internal.h"
+#include "mojo/public/cpp/bindings/lib/validation_errors.h"
+
+namespace mojo {
+namespace internal {
+
+bool ValidateEncodedPointer(const uint64_t* offset) {
+ // Cast to uintptr_t so overflow behavior is well defined.
+ return reinterpret_cast<uintptr_t>(offset) + *offset >=
+ reinterpret_cast<uintptr_t>(offset);
+}
+
+bool ValidateStructHeaderAndClaimMemory(const void* data,
+ BoundsChecker* bounds_checker) {
+ if (!IsAligned(data)) {
+ ReportValidationError(VALIDATION_ERROR_MISALIGNED_OBJECT);
+ return false;
+ }
+ if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
+ return false;
+ }
+
+ const StructHeader* header = static_cast<const StructHeader*>(data);
+
+ if (header->num_bytes < sizeof(StructHeader)) {
+ ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
+ return false;
+ }
+
+ if (!bounds_checker->ClaimMemory(data, header->num_bytes)) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
+ return false;
+ }
+
+ return true;
+}
+
+bool ValidateMessageIsRequestWithoutResponse(const Message* message) {
+ if (message->has_flag(kMessageIsResponse) ||
+ message->has_flag(kMessageExpectsResponse)) {
+ ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
+ return false;
+ }
+ return true;
+}
+
+bool ValidateMessageIsRequestExpectingResponse(const Message* message) {
+ if (message->has_flag(kMessageIsResponse) ||
+ !message->has_flag(kMessageExpectsResponse)) {
+ ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
+ return false;
+ }
+ return true;
+}
+
+bool ValidateMessageIsResponse(const Message* message) {
+ if (message->has_flag(kMessageExpectsResponse) ||
+ !message->has_flag(kMessageIsResponse)) {
+ ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
+ return false;
+ }
+ return true;
+}
+
+} // namespace internal
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698