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

Side by Side Diff: dbus/object_proxy.cc

Issue 9508005: dbus: verify object path of incoming signals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fixes Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « dbus/end_to_end_async_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "dbus/bus.h" 5 #include "dbus/bus.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // We should add the filter only once. Otherwise, HandleMessage() will 297 // We should add the filter only once. Otherwise, HandleMessage() will
298 // be called more than once. 298 // be called more than once.
299 if (!filter_added_) { 299 if (!filter_added_) {
300 if (bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { 300 if (bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this)) {
301 filter_added_ = true; 301 filter_added_ = true;
302 } else { 302 } else {
303 LOG(ERROR) << "Failed to add filter function"; 303 LOG(ERROR) << "Failed to add filter function";
304 } 304 }
305 } 305 }
306 // Add a match rule so the signal goes through HandleMessage(). 306 // Add a match rule so the signal goes through HandleMessage().
307 //
308 // We don't restrict the sender object path to be |object_path_| here,
309 // to make it easy to test D-Bus signal handling with dbus-send, that
310 // uses "/" as the sender object path. We can make the object path
311 // restriction customizable when it becomes necessary.
312 const std::string match_rule = 307 const std::string match_rule =
313 base::StringPrintf("type='signal', interface='%s'", 308 base::StringPrintf("type='signal', interface='%s', path='%s'",
314 interface_name.c_str()); 309 interface_name.c_str(),
310 object_path_.value().c_str());
315 311
316 // Add the match rule if we don't have it. 312 // Add the match rule if we don't have it.
317 if (match_rules_.find(match_rule) == match_rules_.end()) { 313 if (match_rules_.find(match_rule) == match_rules_.end()) {
318 ScopedDBusError error; 314 ScopedDBusError error;
319 bus_->AddMatch(match_rule, error.get());; 315 bus_->AddMatch(match_rule, error.get());;
320 if (error.is_set()) { 316 if (error.is_set()) {
321 LOG(ERROR) << "Failed to add match rule: " << match_rule; 317 LOG(ERROR) << "Failed to add match rule: " << match_rule;
322 } else { 318 } else {
323 // Store the match rule, so that we can remove this in Detach(). 319 // Store the match rule, so that we can remove this in Detach().
324 match_rules_.insert(match_rule); 320 match_rules_.insert(match_rule);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 bus_->AssertOnDBusThread(); 355 bus_->AssertOnDBusThread();
360 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) 356 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL)
361 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 357 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
362 358
363 // raw_message will be unrefed on exit of the function. Increment the 359 // raw_message will be unrefed on exit of the function. Increment the
364 // reference so we can use it in Signal. 360 // reference so we can use it in Signal.
365 dbus_message_ref(raw_message); 361 dbus_message_ref(raw_message);
366 scoped_ptr<Signal> signal( 362 scoped_ptr<Signal> signal(
367 Signal::FromRawMessage(raw_message)); 363 Signal::FromRawMessage(raw_message));
368 364
365 // Verify the signal comes from the object we're proxying for, this is
366 // our last chance to return DBUS_HANDLER_RESULT_NOT_YET_HANDLED and
367 // allow other object proxies to handle instead.
368 const dbus::ObjectPath path = signal->GetPath();
369 if (path != object_path_) {
370 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
371 }
372
369 const std::string interface = signal->GetInterface(); 373 const std::string interface = signal->GetInterface();
370 const std::string member = signal->GetMember(); 374 const std::string member = signal->GetMember();
371 375
372 // Check if we know about the signal. 376 // Check if we know about the signal.
373 const std::string absolute_signal_name = GetAbsoluteSignalName( 377 const std::string absolute_signal_name = GetAbsoluteSignalName(
374 interface, member); 378 interface, member);
375 MethodTable::const_iterator iter = method_table_.find(absolute_signal_name); 379 MethodTable::const_iterator iter = method_table_.find(absolute_signal_name);
376 if (iter == method_table_.end()) { 380 if (iter == method_table_.end()) {
377 // Don't know about the signal. 381 // Don't know about the signal.
378 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 382 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 void ObjectProxy::LogMethodCallFailure( 429 void ObjectProxy::LogMethodCallFailure(
426 const base::StringPiece& error_name, 430 const base::StringPiece& error_name,
427 const base::StringPiece& error_message) const { 431 const base::StringPiece& error_message) const {
428 if (ignore_service_unknown_errors_ && error_name == kErrorServiceUnknown) 432 if (ignore_service_unknown_errors_ && error_name == kErrorServiceUnknown)
429 return; 433 return;
430 LOG(ERROR) << "Failed to call method: " << error_name 434 LOG(ERROR) << "Failed to call method: " << error_name
431 << ": " << error_message; 435 << ": " << error_message;
432 } 436 }
433 437
434 } // namespace dbus 438 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/end_to_end_async_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698