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

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

Issue 1412733002: C++ bindings: separate out serialization source set, have "mojom" targets optionally use serializat… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: address comments from previous patch Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_util.h" 5 #include "mojo/public/cpp/bindings/lib/validation_util.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" 9 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
10 #include "mojo/public/cpp/bindings/lib/message_internal.h"
11 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 10 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
12 11
13 namespace mojo { 12 namespace mojo {
14 namespace internal { 13 namespace internal {
15 14
16 bool ValidateEncodedPointer(const uint64_t* offset) { 15 bool ValidateEncodedPointer(const uint64_t* offset) {
17 // - Make sure |*offset| is no more than 32-bits. 16 // - Make sure |*offset| is no more than 32-bits.
18 // - Cast |offset| to uintptr_t so overflow behavior is well defined across 17 // - Cast |offset| to uintptr_t so overflow behavior is well defined across
19 // 32-bit and 64-bit systems. 18 // 32-bit and 64-bit systems.
20 return *offset <= std::numeric_limits<uint32_t>::max() && 19 return *offset <= std::numeric_limits<uint32_t>::max() &&
(...skipping 21 matching lines...) Expand all
42 } 41 }
43 42
44 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { 43 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) {
45 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); 44 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
46 return false; 45 return false;
47 } 46 }
48 47
49 return true; 48 return true;
50 } 49 }
51 50
52 bool ValidateMessageIsRequestWithoutResponse(const Message* message) {
53 if (message->has_flag(kMessageIsResponse) ||
54 message->has_flag(kMessageExpectsResponse)) {
55 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
56 return false;
57 }
58 return true;
59 }
60
61 bool ValidateMessageIsRequestExpectingResponse(const Message* message) {
62 if (message->has_flag(kMessageIsResponse) ||
63 !message->has_flag(kMessageExpectsResponse)) {
64 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
65 return false;
66 }
67 return true;
68 }
69
70 bool ValidateMessageIsResponse(const Message* message) {
71 if (message->has_flag(kMessageExpectsResponse) ||
72 !message->has_flag(kMessageIsResponse)) {
73 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
74 return false;
75 }
76 return true;
77 }
78
79 } // namespace internal 51 } // namespace internal
80 } // namespace mojo 52 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698