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

Unified Diff: mojo/public/cpp/bindings/lib/control_message_handler.cc

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.cc ('k') | mojo/public/cpp/bindings/lib/control_message_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/control_message_handler.cc
diff --git a/mojo/public/cpp/bindings/lib/control_message_handler.cc b/mojo/public/cpp/bindings/lib/control_message_handler.cc
index b9bf7eb54ed5aaf96078f62181e58a42af7aa4ca..b112489475bd29e525495a1fec9af93c54d6c8a9 100644
--- a/mojo/public/cpp/bindings/lib/control_message_handler.cc
+++ b/mojo/public/cpp/bindings/lib/control_message_handler.cc
@@ -11,10 +11,48 @@
#include "base/logging.h"
#include "mojo/public/cpp/bindings/lib/message_builder.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
+#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
namespace mojo {
namespace internal {
+namespace {
+
+bool ValidateControlRequestWithResponse(Message* message) {
+ ValidationContext validation_context(
+ message->data(), message->data_num_bytes(), message->handles()->size(),
+ message, "ControlRequestValidator");
+ if (!ValidateMessageIsRequestExpectingResponse(message, &validation_context))
+ return false;
+
+ switch (message->header()->name) {
+ case interface_control::kRunMessageId:
+ return ValidateMessagePayload<
+ interface_control::internal::RunMessageParams_Data>(
+ message, &validation_context);
+ }
+ return false;
+}
+
+bool ValidateControlRequestWithoutResponse(Message* message) {
+ ValidationContext validation_context(
+ message->data(), message->data_num_bytes(), message->handles()->size(),
+ message, "ControlRequestValidator");
+ if (!ValidateMessageIsRequestWithoutResponse(message, &validation_context))
+ return false;
+
+ switch (message->header()->name) {
+ case interface_control::kRunOrClosePipeMessageId:
+ return ValidateMessageIsRequestWithoutResponse(message,
+ &validation_context) &&
+ ValidateMessagePayload<
+ interface_control::internal::RunOrClosePipeMessageParams_Data>(
+ message, &validation_context);
+ }
+ return false;
+}
+
+} // namespace
// static
bool ControlMessageHandler::IsControlMessage(const Message* message) {
@@ -30,6 +68,9 @@ ControlMessageHandler::~ControlMessageHandler() {
}
bool ControlMessageHandler::Accept(Message* message) {
+ if (!ValidateControlRequestWithoutResponse(message))
+ return false;
+
if (message->header()->name == interface_control::kRunOrClosePipeMessageId)
return RunOrClosePipe(message);
@@ -40,6 +81,9 @@ bool ControlMessageHandler::Accept(Message* message) {
bool ControlMessageHandler::AcceptWithResponder(
Message* message,
MessageReceiverWithStatus* responder) {
+ if (!ValidateControlRequestWithResponse(message))
+ return false;
+
if (message->header()->name == interface_control::kRunMessageId)
return Run(message, responder);
@@ -61,6 +105,8 @@ bool ControlMessageHandler::Run(Message* message,
output->set_query_version_result(
interface_control::QueryVersionResult::New());
output->get_query_version_result()->version = interface_version_;
+ } else if (input.is_flush_for_testing()) {
+ output.reset();
} else {
output.reset();
}
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.cc ('k') | mojo/public/cpp/bindings/lib/control_message_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698