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

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

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 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" 5 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
6 6
7 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" 7 #include "mojo/public/cpp/bindings/lib/bounds_checker.h"
8 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 8 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
9 #include "mojo/public/cpp/bindings/lib/validation_util.h" 9 #include "mojo/public/cpp/bindings/lib/validation_util.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS); 49 ReportValidationError(VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
50 return false; 50 return false;
51 } 51 }
52 52
53 return true; 53 return true;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink) 58 MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink)
59 : MessageFilter(sink) { 59 : MessageHeaderValidator(sink, "Unknown header validator") {}
60 }
61 60
62 bool MessageHeaderValidator::Accept(Message* message) { 61 MessageHeaderValidator::MessageHeaderValidator(MessageReceiver* sink,
62 const std::string& debug_info)
63 : MessageFilter(sink), debug_info_(debug_info) {}
64
65 MessageReceiver::Result MessageHeaderValidator::Accept(Message* message) {
63 // Pass 0 as number of handles because we don't expect any in the header, even 66 // Pass 0 as number of handles because we don't expect any in the header, even
64 // if |message| contains handles. 67 // if |message| contains handles.
65 BoundsChecker bounds_checker(message->data(), message->data_num_bytes(), 0); 68 BoundsChecker bounds_checker(message->data(), message->data_num_bytes(), 0);
66 69
67 if (!ValidateStructHeaderAndClaimMemory(message->data(), &bounds_checker)) 70 if (!ValidateStructHeaderAndClaimMemory(message->data(), &bounds_checker))
68 return false; 71 return Result::ForBadMessage(debug_info_, message);
69 72
70 if (!IsValidMessageHeader(message->header())) 73 if (!IsValidMessageHeader(message->header()))
71 return false; 74 return Result::ForBadMessage(debug_info_, message);
72 75
73 return sink_->Accept(message); 76 return sink_->Accept(message);
74 } 77 }
75 78
76 } // namespace internal 79 } // namespace internal
77 } // namespace mojo 80 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698