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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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/validation_util.h ('k') | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "mojo/public/cpp/bindings/lib/validation_util.h"
6
7 #include <limits>
8 #include <string>
9
10 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
11 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
12
13 namespace mojo {
14 namespace internal {
15
16 bool ValidateEncodedPointer(const uint64_t* offset) {
17 // - Make sure |*offset| is no more than 32-bits.
18 // - Cast |offset| to uintptr_t so overflow behavior is well defined across
19 // 32-bit and 64-bit systems.
20 return *offset <= std::numeric_limits<uint32_t>::max() &&
21 (reinterpret_cast<uintptr_t>(offset) +
22 static_cast<uint32_t>(*offset) >=
23 reinterpret_cast<uintptr_t>(offset));
24 }
25
26 ValidationError ValidateStructHeaderAndClaimMemory(
27 const void* data,
28 BoundsChecker* bounds_checker,
29 std::string* err) {
30 if (!IsAligned(data)) {
31 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
32 return ValidationError::MISALIGNED_OBJECT;
33 }
34 if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) {
35 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
36 return ValidationError::ILLEGAL_MEMORY_RANGE;
37 }
38
39 const StructHeader* header = static_cast<const StructHeader*>(data);
40
41 if (header->num_bytes < sizeof(StructHeader)) {
42 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
43 return ValidationError::UNEXPECTED_STRUCT_HEADER;
44 }
45
46 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) {
47 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
48 return ValidationError::ILLEGAL_MEMORY_RANGE;
49 }
50
51 return ValidationError::NONE;
52 }
53
54 } // namespace internal
55 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698