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

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

Issue 2844143002: Mojo C++ bindings: reject messages version 2 with null payload pointer. (Closed)
Patch Set: . Created 3 years, 7 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/message.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_header_validator.h" 5 #include "mojo/public/cpp/bindings/message_header_validator.h"
6 6
7 #include "mojo/public/cpp/bindings/lib/array_internal.h" 7 #include "mojo/public/cpp/bindings/lib/array_internal.h"
8 #include "mojo/public/cpp/bindings/lib/validate_params.h" 8 #include "mojo/public/cpp/bindings/lib/validate_params.h"
9 #include "mojo/public/cpp/bindings/lib/validation_context.h" 9 #include "mojo/public/cpp/bindings/lib/validation_context.h"
10 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 10 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 auto* header_v2 = static_cast<const internal::MessageHeaderV2*>(header); 67 auto* header_v2 = static_cast<const internal::MessageHeaderV2*>(header);
68 // For the payload pointer: 68 // For the payload pointer:
69 // - Check that the pointer can be safely decoded. 69 // - Check that the pointer can be safely decoded.
70 // - Claim one byte that the pointer points to. It makes sure not only the 70 // - Claim one byte that the pointer points to. It makes sure not only the
71 // address is within the message, but also the address precedes the array 71 // address is within the message, but also the address precedes the array
72 // storing interface IDs (which is important for safely calculating the 72 // storing interface IDs (which is important for safely calculating the
73 // payload size). 73 // payload size).
74 // - Validation of the payload contents will be done separately based on the 74 // - Validation of the payload contents will be done separately based on the
75 // payload type. 75 // payload type.
76 if (!header_v2->payload.is_null() && 76 if (!internal::ValidatePointerNonNullable(header_v2->payload,
77 (!internal::ValidatePointer(header_v2->payload, validation_context) || 77 "null payload in message header",
78 !validation_context->ClaimMemory(header_v2->payload.Get(), 1))) { 78 validation_context) ||
79 !internal::ValidatePointer(header_v2->payload, validation_context) ||
80 !validation_context->ClaimMemory(header_v2->payload.Get(), 1)) {
79 return false; 81 return false;
80 } 82 }
81 83
82 const internal::ContainerValidateParams validate_params(0, false, nullptr); 84 const internal::ContainerValidateParams validate_params(0, false, nullptr);
83 if (!internal::ValidateContainer(header_v2->payload_interface_ids, 85 if (!internal::ValidateContainer(header_v2->payload_interface_ids,
84 validation_context, &validate_params)) { 86 validation_context, &validate_params)) {
85 return false; 87 return false;
86 } 88 }
87 89
88 if (!header_v2->payload_interface_ids.is_null()) { 90 if (!header_v2->payload_interface_ids.is_null()) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 &validation_context)) 126 &validation_context))
125 return false; 127 return false;
126 128
127 if (!IsValidMessageHeader(message->header(), &validation_context)) 129 if (!IsValidMessageHeader(message->header(), &validation_context))
128 return false; 130 return false;
129 131
130 return true; 132 return true;
131 } 133 }
132 134
133 } // namespace mojo 135 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698