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

Side by Side Diff: mojo/public/cpp/bindings/lib/bounds_checker.h

Issue 289333002: Mojo cpp bindings: validation logic for incoming messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify BoundsChecker Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BOUNDS_CHECKER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BOUNDS_CHECKER_H_
7
8 #include <stdint.h>
9
10 #include "mojo/public/cpp/system/macros.h"
11
12 namespace mojo {
13
14 class Handle;
15
16 namespace internal {
17
18 // BoundsChecker is used to validate object sizes, pointers and handle indices
19 // for payload of incoming messages.
20 class BoundsChecker {
21 public:
22 // [data, data + data_num_bytes) specifies the valid memory range.
23 // [0, num_handles) specifies the valid range of handle indices.
24 BoundsChecker(const void* data, uint32_t data_num_bytes,
25 size_t num_handles);
26
27 ~BoundsChecker();
28
29 // Claims the specified memory range.
30 // The method succeeds if the range is within the unclaimed range. (Please see
31 // the comments for IsWithinUnclaimedRange().)
32 bool ClaimMemory(const void* position, uint32_t num_bytes);
33
34 // Claims the specified encoded handle (which is basically a handle index).
35 // The method succeeds if:
36 // - |encoded_handle|'s value is |kEncodedInvalidHandleValue|, or
37 // - the handle is contained inside the valid range of handle indices, and
38 // greater than the max handle index that has been claimed.
39 bool ClaimHandle(const Handle& encoded_handle);
40
41 // Returns true if:
42 // - the specified range is not empty, and
43 // - the range is contained inside the valid memory range, and
44 // - |position| is greater than the max address that has been claimed.
45 bool IsWithinUnclaimedRange(const void* position, uint32_t num_bytes) const;
Tom Sepez 2014/05/28 17:12:52 nit: Looks like when this is used outside of tests
yzshen1 2014/05/28 17:27:52 One issue is that the opposite of "within unclaime
46
47 private:
48 bool InternalIsWithinUnclaimedRange(uintptr_t begin, uintptr_t end) const;
49
50 // [unclaimed_data_begin_, data_end_) is the unclaimed memory range.
51 uintptr_t unclaimed_data_begin_;
52 uintptr_t data_end_;
53
54 // [unclaimed_handle_begin_, handle_end_) is the unclaimed handle index range.
55 uint32_t unclaimed_handle_begin_;
56 uint32_t handle_end_;
57
58 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChecker);
59 };
60
61 } // namespace internal
62 } // namespace mojo
63
64 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BOUNDS_CHECKER_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_serialization.cc ('k') | mojo/public/cpp/bindings/lib/bounds_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698