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

Side by Side Diff: mojo/public/cpp/bindings/lib/pipe_control_message_handler.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 2015 The Chromium Authors. All rights reserved. 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 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/pipe_control_message_handler.h" 5 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/public/cpp/bindings/lib/message_builder.h" 8 #include "mojo/public/cpp/bindings/lib/message_builder.h"
9 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h" 9 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h"
10 #include "mojo/public/cpp/bindings/lib/serialization.h" 10 #include "mojo/public/cpp/bindings/lib/serialization.h"
11 #include "mojo/public/cpp/bindings/lib/validation_context.h"
11 #include "mojo/public/cpp/bindings/lib/validation_util.h" 12 #include "mojo/public/cpp/bindings/lib/validation_util.h"
12 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" 13 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace internal { 16 namespace internal {
16 17
17 PipeControlMessageHandler::PipeControlMessageHandler( 18 PipeControlMessageHandler::PipeControlMessageHandler(
18 PipeControlMessageHandlerDelegate* delegate) 19 PipeControlMessageHandlerDelegate* delegate)
19 : delegate_(delegate) {} 20 : delegate_(delegate) {}
20 21
21 PipeControlMessageHandler::~PipeControlMessageHandler() {} 22 PipeControlMessageHandler::~PipeControlMessageHandler() {}
22 23
24 void PipeControlMessageHandler::SetDescription(const std::string& description) {
25 description_ = description;
26 }
27
23 // static 28 // static
24 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) { 29 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) {
25 return !IsValidInterfaceId(message->interface_id()); 30 return !IsValidInterfaceId(message->interface_id());
26 } 31 }
27 32
28 bool PipeControlMessageHandler::Accept(Message* message) { 33 bool PipeControlMessageHandler::Accept(Message* message) {
29 if (!Validate(message)) 34 if (!Validate(message))
30 return false; 35 return false;
31 36
32 if (message->name() == pipe_control::kRunOrClosePipeMessageId) 37 if (message->name() == pipe_control::kRunOrClosePipeMessageId)
33 return RunOrClosePipe(message); 38 return RunOrClosePipe(message);
34 39
35 NOTREACHED(); 40 NOTREACHED();
36 return false; 41 return false;
37 } 42 }
38 43
39 bool PipeControlMessageHandler::Validate(const Message* message) { 44 bool PipeControlMessageHandler::Validate(Message* message) {
45 ValidationContext validation_context(
46 message->data(), message->data_num_bytes(), 0, message, description_);
47
40 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { 48 if (message->name() == pipe_control::kRunOrClosePipeMessageId) {
41 if (!ValidateMessageIsRequestWithoutResponse(message)) 49 if (!ValidateMessageIsRequestWithoutResponse(message, &validation_context))
42 return false; 50 return false;
43 return ValidateMessagePayload< 51 return ValidateMessagePayload<
44 pipe_control::internal::RunOrClosePipeMessageParams_Data>(message); 52 pipe_control::internal::RunOrClosePipeMessageParams_Data>(
53 message, &validation_context);
45 } 54 }
46 55
47 return false; 56 return false;
48 } 57 }
49 58
50 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { 59 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) {
51 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = 60 pipe_control::internal::RunOrClosePipeMessageParams_Data* params =
52 reinterpret_cast< 61 reinterpret_cast<
53 pipe_control::internal::RunOrClosePipeMessageParams_Data*>( 62 pipe_control::internal::RunOrClosePipeMessageParams_Data*>(
54 message->mutable_payload()); 63 message->mutable_payload());
(...skipping 13 matching lines...) Expand all
68 ->id); 77 ->id);
69 } 78 }
70 79
71 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " 80 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control "
72 << "message. Closing the pipe."; 81 << "message. Closing the pipe.";
73 return false; 82 return false;
74 } 83 }
75 84
76 } // namespace internal 85 } // namespace internal
77 } // namespace mojo 86 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698