Commit c827ad1c authored by sergeyu's avatar sergeyu Committed by Commit bot

Fix remoting NM hosts to verify that incoming messages are dictionaries.

After crrev.com/295851 the PipeMessagingChannel verifies that incoming
messages are dictionaries and then passes them as base::Value to
OnMessage() and then OnMessage() implementation static_cast<> them to
base::DictionaryValue. This is fragile, and also it shouldn't be
PipeMessagingChannel's responsibility to verify format of the messages
it reads. Moved the check to OnMessage() implementations.

Review URL: https://codereview.chromium.org/615543004

Cr-Commit-Position: refs/heads/master@{#297274}
parent b3558eef
...@@ -87,6 +87,12 @@ void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) { ...@@ -87,6 +87,12 @@ void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) {
void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
DCHECK(task_runner()->BelongsToCurrentThread()); DCHECK(task_runner()->BelongsToCurrentThread());
if (message->GetType() != base::Value::TYPE_DICTIONARY) {
LOG(ERROR) << "Received a message that's not a dictionary.";
channel_->SendMessage(nullptr);
return;
}
scoped_ptr<base::DictionaryValue> message_dict( scoped_ptr<base::DictionaryValue> message_dict(
static_cast<base::DictionaryValue*>(message.release())); static_cast<base::DictionaryValue*>(message.release()));
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
......
...@@ -72,12 +72,6 @@ void PipeMessagingChannel::Start(EventHandler* event_handler) { ...@@ -72,12 +72,6 @@ void PipeMessagingChannel::Start(EventHandler* event_handler) {
void PipeMessagingChannel::ProcessMessage(scoped_ptr<base::Value> message) { void PipeMessagingChannel::ProcessMessage(scoped_ptr<base::Value> message) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (message->GetType() != base::Value::TYPE_DICTIONARY) {
LOG(ERROR) << "Expected DictionaryValue";
Shutdown();
return;
}
if (event_handler_) if (event_handler_)
event_handler_->OnMessage(message.Pass()); event_handler_->OnMessage(message.Pass());
} }
......
...@@ -104,6 +104,12 @@ void Me2MeNativeMessagingHost::Start( ...@@ -104,6 +104,12 @@ void Me2MeNativeMessagingHost::Start(
void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (message->GetType() != base::Value::TYPE_DICTIONARY) {
LOG(ERROR) << "Received a message that's not a dictionary.";
channel_->SendMessage(nullptr);
return;
}
scoped_ptr<base::DictionaryValue> message_dict( scoped_ptr<base::DictionaryValue> message_dict(
static_cast<base::DictionaryValue*>(message.release())); static_cast<base::DictionaryValue*>(message.release()));
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment