1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "mojo/public/cpp/bindings/lib/validation_context.h" 6 7 #include "base/logging.h" 8 9 namespace mojo { 10 namespace internal { 11 12 ValidationContext::ValidationContext(const void* data, 13 size_t data_num_bytes, 14 size_t num_handles, 15 size_t num_associated_endpoint_handles, 16 Message* message, 17 const base::StringPiece& description, 18 int stack_depth) 19 : message_(message), 20 description_(description), 21 data_begin_(reinterpret_cast<uintptr_t>(data)), 22 data_end_(data_begin_ + data_num_bytes), 23 handle_begin_(0), 24 handle_end_(static_cast<uint32_t>(num_handles)), 25 associated_endpoint_handle_begin_(0), 26 associated_endpoint_handle_end_( 27 static_cast<uint32_t>(num_associated_endpoint_handles)), 28 stack_depth_(stack_depth) { 29 // Check whether the calculation of |data_end_| or static_cast from size_t to 30 // uint32_t causes overflow. 31 // They shouldn't happen but they do, set the corresponding range to empty. 32 if (data_end_ < data_begin_) { 33 NOTREACHED(); 34 data_end_ = data_begin_; 35 } 36 if (handle_end_ < num_handles) { 37 NOTREACHED(); 38 handle_end_ = 0; 39 } 40 if (associated_endpoint_handle_end_ < num_associated_endpoint_handles) { 41 NOTREACHED(); 42 associated_endpoint_handle_end_ = 0; 43 } 44 } 45 46 ValidationContext::~ValidationContext() { 47 } 48 49 } // namespace internal 50 } // namespace mojo 51