0

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}
This commit is contained in:
sergeyu
2014-09-29 14:30:22 -07:00
committed by Commit bot
parent b3558eef5f
commit c827ad1c74
3 changed files with 12 additions and 6 deletions

@ -87,6 +87,12 @@ void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) {
void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
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(
static_cast<base::DictionaryValue*>(message.release()));
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());

@ -72,12 +72,6 @@ void PipeMessagingChannel::Start(EventHandler* event_handler) {
void PipeMessagingChannel::ProcessMessage(scoped_ptr<base::Value> message) {
DCHECK(CalledOnValidThread());
if (message->GetType() != base::Value::TYPE_DICTIONARY) {
LOG(ERROR) << "Expected DictionaryValue";
Shutdown();
return;
}
if (event_handler_)
event_handler_->OnMessage(message.Pass());
}

@ -104,6 +104,12 @@ void Me2MeNativeMessagingHost::Start(
void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
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(
static_cast<base::DictionaryValue*>(message.release()));
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());