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

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

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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
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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
7 7
8 #include "mojo/public/cpp/bindings/lib/array_internal.h" 8 #include "mojo/public/cpp/bindings/lib/array_internal.h"
9 #include "mojo/public/cpp/bindings/lib/validate_params.h" 9 #include "mojo/public/cpp/bindings/lib/validate_params.h"
10 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 10 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
11 #include "mojo/public/cpp/bindings/lib/validation_util.h" 11 #include "mojo/public/cpp/bindings/lib/validation_util.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace internal { 14 namespace internal {
15 15
16 // Map serializes into a struct which has two arrays as struct fields, the keys 16 // Map serializes into a struct which has two arrays as struct fields, the keys
17 // and the values. 17 // and the values.
18 template <typename Key, typename Value> 18 template <typename Key, typename Value>
19 class Map_Data { 19 class Map_Data {
20 public: 20 public:
21 static Map_Data* New(Buffer* buf) { 21 static Map_Data* New(Buffer* buf) {
22 return new (buf->Allocate(sizeof(Map_Data))) Map_Data(); 22 return new (buf->Allocate(sizeof(Map_Data))) Map_Data();
23 } 23 }
24 24
25 // |validate_params| must have non-null |key_validate_params| and 25 // |validate_params| must have non-null |key_validate_params| and
26 // |element_validate_params| members. 26 // |element_validate_params| members.
27 static bool Validate(const void* data, 27 static bool Validate(const void* data,
28 BoundsChecker* bounds_checker, 28 ValidationContext* validation_context,
29 const ContainerValidateParams* validate_params) { 29 const ContainerValidateParams* validate_params) {
30 if (!data) 30 if (!data)
31 return true; 31 return true;
32 32
33 if (!ValidateStructHeaderAndClaimMemory(data, bounds_checker)) 33 if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
34 return false; 34 return false;
35 35
36 const Map_Data* object = static_cast<const Map_Data*>(data); 36 const Map_Data* object = static_cast<const Map_Data*>(data);
37 if (object->header_.num_bytes != sizeof(Map_Data) || 37 if (object->header_.num_bytes != sizeof(Map_Data) ||
38 object->header_.version != 0) { 38 object->header_.version != 0) {
39 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER); 39 ReportValidationError(validation_context,
40 VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
40 return false; 41 return false;
41 } 42 }
42 43
43 if (!ValidateEncodedPointer(&object->keys.offset)) { 44 if (!ValidateEncodedPointer(&object->keys.offset)) {
44 ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER); 45 ReportValidationError(validation_context,
46 VALIDATION_ERROR_ILLEGAL_POINTER);
45 return false; 47 return false;
46 } 48 }
47 if (!object->keys.offset) { 49 if (!object->keys.offset) {
48 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 50 ReportValidationError(validation_context,
51 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
49 "null key array in map struct"); 52 "null key array in map struct");
50 return false; 53 return false;
51 } 54 }
52 if (!Array_Data<Key>::Validate(DecodePointerRaw(&object->keys.offset), 55 if (!Array_Data<Key>::Validate(DecodePointerRaw(&object->keys.offset),
53 bounds_checker, 56 validation_context,
54 validate_params->key_validate_params)) { 57 validate_params->key_validate_params)) {
55 return false; 58 return false;
56 } 59 }
57 60
58 if (!ValidateEncodedPointer(&object->values.offset)) { 61 if (!ValidateEncodedPointer(&object->values.offset)) {
59 ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER); 62 ReportValidationError(validation_context,
63 VALIDATION_ERROR_ILLEGAL_POINTER);
60 return false; 64 return false;
61 } 65 }
62 if (!object->values.offset) { 66 if (!object->values.offset) {
63 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 67 ReportValidationError(validation_context,
68 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
64 "null value array in map struct"); 69 "null value array in map struct");
65 return false; 70 return false;
66 } 71 }
67 if (!Array_Data<Value>::Validate( 72 if (!Array_Data<Value>::Validate(
68 DecodePointerRaw(&object->values.offset), 73 DecodePointerRaw(&object->values.offset),
69 bounds_checker, validate_params->element_validate_params)) { 74 validation_context, validate_params->element_validate_params)) {
70 return false; 75 return false;
71 } 76 }
72 77
73 const ArrayHeader* key_header = 78 const ArrayHeader* key_header =
74 static_cast<const ArrayHeader*>(DecodePointerRaw(&object->keys.offset)); 79 static_cast<const ArrayHeader*>(DecodePointerRaw(&object->keys.offset));
75 const ArrayHeader* value_header = static_cast<const ArrayHeader*>( 80 const ArrayHeader* value_header = static_cast<const ArrayHeader*>(
76 DecodePointerRaw(&object->values.offset)); 81 DecodePointerRaw(&object->values.offset));
77 if (key_header->num_elements != value_header->num_elements) { 82 if (key_header->num_elements != value_header->num_elements) {
78 ReportValidationError(VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP); 83 ReportValidationError(validation_context,
84 VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP);
79 return false; 85 return false;
80 } 86 }
81 87
82 return true; 88 return true;
83 } 89 }
84 90
85 StructHeader header_; 91 StructHeader header_;
86 92
87 Pointer<Array_Data<Key>> keys; 93 Pointer<Array_Data<Key>> keys;
88 Pointer<Array_Data<Value>> values; 94 Pointer<Array_Data<Value>> values;
(...skipping 14 matching lines...) Expand all
103 header_.version = 0; 109 header_.version = 0;
104 } 110 }
105 ~Map_Data() = delete; 111 ~Map_Data() = delete;
106 }; 112 };
107 static_assert(sizeof(Map_Data<char, char>) == 24, "Bad sizeof(Map_Data)"); 113 static_assert(sizeof(Map_Data<char, char>) == 24, "Bad sizeof(Map_Data)");
108 114
109 } // namespace internal 115 } // namespace internal
110 } // namespace mojo 116 } // namespace mojo
111 117
112 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_ 118 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_ptr_state.h ('k') | mojo/public/cpp/bindings/lib/message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698