| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef THIRD_PARTY_MOJO_SRC_MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | |
| 6 #define THIRD_PARTY_MOJO_SRC_MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "third_party/mojo/src/mojo/public/cpp/bindings/lib/bounds_checker.h" | |
| 11 #include "third_party/mojo/src/mojo/public/cpp/bindings/message.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 namespace internal { | |
| 15 | |
| 16 // Checks whether decoding the pointer will overflow and produce a pointer | |
| 17 // smaller than |offset|. | |
| 18 bool ValidateEncodedPointer(const uint64_t* offset); | |
| 19 | |
| 20 // Validates that |data| contains a valid struct header, in terms of alignment | |
| 21 // and size (i.e., the |num_bytes| field of the header is sufficient for storing | |
| 22 // the header itself). Besides, it checks that the memory range | |
| 23 // [data, data + num_bytes) is not marked as occupied by other objects in | |
| 24 // |bounds_checker|. On success, the memory range is marked as occupied. | |
| 25 // Note: Does not verify |version| or that |num_bytes| is correct for the | |
| 26 // claimed version. | |
| 27 bool ValidateStructHeaderAndClaimMemory(const void* data, | |
| 28 BoundsChecker* bounds_checker); | |
| 29 | |
| 30 // Validates that the message is a request which doesn't expect a response. | |
| 31 bool ValidateMessageIsRequestWithoutResponse(const Message* message); | |
| 32 // Validates that the message is a request expecting a response. | |
| 33 bool ValidateMessageIsRequestExpectingResponse(const Message* message); | |
| 34 // Validates that the message is a response. | |
| 35 bool ValidateMessageIsResponse(const Message* message); | |
| 36 | |
| 37 // Validates that the message payload is a valid struct of type ParamsType. | |
| 38 template <typename ParamsType> | |
| 39 bool ValidateMessagePayload(const Message* message) { | |
| 40 BoundsChecker bounds_checker(message->payload(), message->payload_num_bytes(), | |
| 41 message->handles()->size()); | |
| 42 return ParamsType::Validate(message->payload(), &bounds_checker); | |
| 43 } | |
| 44 | |
| 45 // The following methods validate control messages defined in | |
| 46 // interface_control_messages.mojom. | |
| 47 bool ValidateControlRequest(const Message* message); | |
| 48 bool ValidateControlResponse(const Message* message); | |
| 49 | |
| 50 } // namespace internal | |
| 51 } // namespace mojo | |
| 52 | |
| 53 #endif // THIRD_PARTY_MOJO_SRC_MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_UTIL_H_ | |
| OLD | NEW |