aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/lib/validation_context.cc
diff options
context:
space:
mode:
authorJay Civelli <jcivelli@google.com>2017-03-29 16:17:00 -0700
committerJay Civelli <jcivelli@google.com>2017-07-24 13:31:43 -0700
commit8ac9103e05b66812c25348943383f9365d1ce3e0 (patch)
tree63a61c9698e719de1a24de6fca21e29401f92842 /mojo/public/cpp/bindings/lib/validation_context.cc
parent24543f227908c2e949bb9a15b40276f59fcc9a0a (diff)
downloadlibmojo-8ac9103e05b66812c25348943383f9365d1ce3e0.tar.gz
libmojo: Uprev the library to r456626 from Chromium
Pulled the latest and greatest version of libmojo from Chromium. The merge was done against r456626 which corresponds to git commit 08266b3fca707804065a2cfd60331722ade41969 of Mar 14, 2017 Notable changes are: - generated binding files are now split in 2 files, interface.mojom.h and interface.mojom-shared.h Change-Id: Idcfd27310e2c9d3c452b671c7ff7a755c3963618
Diffstat (limited to 'mojo/public/cpp/bindings/lib/validation_context.cc')
-rw-r--r--mojo/public/cpp/bindings/lib/validation_context.cc66
1 files changed, 15 insertions, 51 deletions
diff --git a/mojo/public/cpp/bindings/lib/validation_context.cc b/mojo/public/cpp/bindings/lib/validation_context.cc
index a95e07e..ad0a364 100644
--- a/mojo/public/cpp/bindings/lib/validation_context.cc
+++ b/mojo/public/cpp/bindings/lib/validation_context.cc
@@ -4,13 +4,7 @@
#include "mojo/public/cpp/bindings/lib/validation_context.h"
-#include <stddef.h>
-#include <stdint.h>
-
#include "base/logging.h"
-#include "mojo/public/cpp/bindings/lib/serialization_util.h"
-#include "mojo/public/cpp/bindings/message.h"
-#include "mojo/public/cpp/system/handle.h"
namespace mojo {
namespace internal {
@@ -18,69 +12,39 @@ namespace internal {
ValidationContext::ValidationContext(const void* data,
size_t data_num_bytes,
size_t num_handles,
+ size_t num_associated_endpoint_handles,
Message* message,
- const base::StringPiece& description)
+ const base::StringPiece& description,
+ int stack_depth)
: message_(message),
description_(description),
data_begin_(reinterpret_cast<uintptr_t>(data)),
data_end_(data_begin_ + data_num_bytes),
handle_begin_(0),
- handle_end_(static_cast<uint32_t>(num_handles)) {
+ handle_end_(static_cast<uint32_t>(num_handles)),
+ associated_endpoint_handle_begin_(0),
+ associated_endpoint_handle_end_(
+ static_cast<uint32_t>(num_associated_endpoint_handles)),
+ stack_depth_(stack_depth) {
+ // Check whether the calculation of |data_end_| or static_cast from size_t to
+ // uint32_t causes overflow.
+ // They shouldn't happen but they do, set the corresponding range to empty.
if (data_end_ < data_begin_) {
- // The calculation of |data_end_| overflowed.
- // It shouldn't happen but if it does, set the range to empty so
- // IsValidRange() and ClaimMemory() always fail.
NOTREACHED();
data_end_ = data_begin_;
}
if (handle_end_ < num_handles) {
- // Assigning |num_handles| to |handle_end_| overflowed.
- // It shouldn't happen but if it does, set the handle index range to empty.
NOTREACHED();
handle_end_ = 0;
}
+ if (associated_endpoint_handle_end_ < num_associated_endpoint_handles) {
+ NOTREACHED();
+ associated_endpoint_handle_end_ = 0;
+ }
}
ValidationContext::~ValidationContext() {
}
-bool ValidationContext::ClaimMemory(const void* position, uint32_t num_bytes) {
- uintptr_t begin = reinterpret_cast<uintptr_t>(position);
- uintptr_t end = begin + num_bytes;
-
- if (!InternalIsValidRange(begin, end))
- return false;
-
- data_begin_ = end;
- return true;
-}
-
-bool ValidationContext::ClaimHandle(const Handle_Data& encoded_handle) {
- uint32_t index = encoded_handle.value;
- if (index == kEncodedInvalidHandleValue)
- return true;
-
- if (index < handle_begin_ || index >= handle_end_)
- return false;
-
- // |index| + 1 shouldn't overflow, because |index| is not the max value of
- // uint32_t (it is less than |handle_end_|).
- handle_begin_ = index + 1;
- return true;
-}
-
-bool ValidationContext::IsValidRange(const void* position,
- uint32_t num_bytes) const {
- uintptr_t begin = reinterpret_cast<uintptr_t>(position);
- uintptr_t end = begin + num_bytes;
-
- return InternalIsValidRange(begin, end);
-}
-
-bool ValidationContext::InternalIsValidRange(uintptr_t begin,
- uintptr_t end) const {
- return end > begin && begin >= data_begin_ && end <= data_end_;
-}
-
} // namespace internal
} // namespace mojo