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

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_context.cc

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 2014 The Chromium Authors. All rights reserved. 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 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 #include "mojo/public/cpp/bindings/lib/validation_context.h" 5 #include "mojo/public/cpp/bindings/lib/validation_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace mojo { 9 namespace mojo {
10 namespace internal { 10 namespace internal {
11 11
12 ValidationContext::ValidationContext(const void* data, 12 ValidationContext::ValidationContext(const void* data,
13 size_t data_num_bytes, 13 size_t data_num_bytes,
14 size_t num_handles, 14 size_t num_handles,
15 Message* message, 15 Message* message,
16 const base::StringPiece& description) 16 const base::StringPiece& description,
17 int stack_depth)
17 : message_(message), 18 : message_(message),
18 description_(description), 19 description_(description),
19 data_begin_(reinterpret_cast<uintptr_t>(data)), 20 data_begin_(reinterpret_cast<uintptr_t>(data)),
20 data_end_(data_begin_ + data_num_bytes), 21 data_end_(data_begin_ + data_num_bytes),
21 handle_begin_(0), 22 handle_begin_(0),
22 handle_end_(static_cast<uint32_t>(num_handles)) { 23 handle_end_(static_cast<uint32_t>(num_handles)),
24 stack_depth_(stack_depth) {
23 if (data_end_ < data_begin_) { 25 if (data_end_ < data_begin_) {
24 // The calculation of |data_end_| overflowed. 26 // The calculation of |data_end_| overflowed.
25 // It shouldn't happen but if it does, set the range to empty so 27 // It shouldn't happen but if it does, set the range to empty so
26 // IsValidRange() and ClaimMemory() always fail. 28 // IsValidRange() and ClaimMemory() always fail.
27 NOTREACHED(); 29 NOTREACHED();
28 data_end_ = data_begin_; 30 data_end_ = data_begin_;
29 } 31 }
30 if (handle_end_ < num_handles) { 32 if (handle_end_ < num_handles) {
31 // Assigning |num_handles| to |handle_end_| overflowed. 33 // Assigning |num_handles| to |handle_end_| overflowed.
32 // It shouldn't happen but if it does, set the handle index range to empty. 34 // It shouldn't happen but if it does, set the handle index range to empty.
33 NOTREACHED(); 35 NOTREACHED();
34 handle_end_ = 0; 36 handle_end_ = 0;
35 } 37 }
36 } 38 }
37 39
38 ValidationContext::~ValidationContext() { 40 ValidationContext::~ValidationContext() {
39 } 41 }
40 42
41 } // namespace internal 43 } // namespace internal
42 } // namespace mojo 44 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698