0

bt/dbus: Fix response not sent CHECKs

https://crrev.com/c/6325811 adds a CHECK to require that all
dbus exported methods send out a response. This CL fixes
the cases found in bluetooth dbus code.

Bug: 402031736, b:400758194
Change-Id: Ie044635f39058ff9aaa8487c84b5cc94d3147d5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6341127
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Auto-Submit: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1430570}
This commit is contained in:
Xiyuan Xia
2025-03-10 17:06:31 -07:00
committed by Chromium LUCI CQ
parent fea53b17fe
commit b8e4bf1adb
6 changed files with 82 additions and 21 deletions

@ -97,9 +97,14 @@ void BluetoothAdvertisementMonitorServiceProviderImpl::Release(
dbus::ExportedObject::ResponseSender response_sender) {
if (!delegate_) {
DVLOG(2) << "Could not forward D-Bus callback: Invalid delegate";
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(method_call, DBUS_ERROR_FAILED,
"Invalid delegate."));
return;
}
delegate_->OnRelease();
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
void BluetoothAdvertisementMonitorServiceProviderImpl::Activate(
@ -107,9 +112,14 @@ void BluetoothAdvertisementMonitorServiceProviderImpl::Activate(
dbus::ExportedObject::ResponseSender response_sender) {
if (!delegate_) {
DVLOG(2) << "Could not forward D-Bus callback: Invalid delegate";
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(method_call, DBUS_ERROR_FAILED,
"Invalid delegate."));
return;
}
delegate_->OnActivate();
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
void BluetoothAdvertisementMonitorServiceProviderImpl::DeviceFound(
@ -117,6 +127,9 @@ void BluetoothAdvertisementMonitorServiceProviderImpl::DeviceFound(
dbus::ExportedObject::ResponseSender response_sender) {
if (!delegate_) {
DVLOG(2) << "Could not forward D-Bus callback: Invalid delegate";
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(method_call, DBUS_ERROR_FAILED,
"Invalid delegate."));
return;
}
@ -125,9 +138,14 @@ void BluetoothAdvertisementMonitorServiceProviderImpl::DeviceFound(
if (!reader.PopObjectPath(&device_path)) {
LOG(WARNING) << "DeviceFound called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
delegate_->OnDeviceFound(device_path);
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
void BluetoothAdvertisementMonitorServiceProviderImpl::DeviceLost(
@ -135,16 +153,25 @@ void BluetoothAdvertisementMonitorServiceProviderImpl::DeviceLost(
dbus::ExportedObject::ResponseSender response_sender) {
if (!delegate_) {
DVLOG(2) << "Could not forward D-Bus callback: Invalid delegate";
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(method_call, DBUS_ERROR_FAILED,
"Invalid delegate."));
return;
}
dbus::MessageReader reader(method_call);
dbus::ObjectPath device_path;
if (!reader.PopObjectPath(&device_path)) {
LOG(WARNING) << "DeviceLost called with incorrect paramters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
delegate_->OnDeviceLost(device_path);
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
void BluetoothAdvertisementMonitorServiceProviderImpl::WriteProperties(

@ -18,6 +18,14 @@
namespace bluez {
namespace {
std::unique_ptr<dbus::MethodCall> CreateDbusCall() {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
method_call->SetSerial(123); // Fake serial to generate a response message.
return method_call;
}
class FakeBluetoothAdvertisementMonitorServiceProviderDelegate
: public BluetoothAdvertisementMonitorServiceProvider::Delegate {
public:
@ -84,8 +92,7 @@ void SetUpMocksDbus(dbus::MockBus* mock_bus,
} // namespace
TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, Activate) {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
auto method_call = CreateDbusCall();
FakeBluetoothAdvertisementMonitorServiceProviderDelegate delegate;
dbus::Bus::Options options;
@ -109,8 +116,7 @@ TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, Activate) {
}
TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, Release) {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
auto method_call = CreateDbusCall();
FakeBluetoothAdvertisementMonitorServiceProviderDelegate delegate;
dbus::Bus::Options options;
@ -134,8 +140,7 @@ TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, Release) {
}
TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceFound) {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
auto method_call = CreateDbusCall();
dbus::MessageWriter writer(method_call.get());
auto device_path = dbus::ObjectPath("/device/path");
@ -165,8 +170,7 @@ TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceFound) {
}
TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceFoundFailure) {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
auto method_call = CreateDbusCall();
FakeBluetoothAdvertisementMonitorServiceProviderDelegate delegate;
@ -191,8 +195,7 @@ TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceFoundFailure) {
}
TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceLost) {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
auto method_call = CreateDbusCall();
dbus::MessageWriter writer(method_call.get());
auto device_path = dbus::ObjectPath("/device/path");
@ -222,8 +225,7 @@ TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceLost) {
}
TEST(BluetoothAdvertisementMonitorServiceProviderImplTest, DeviceLostFailure) {
auto method_call =
std::make_unique<dbus::MethodCall>("com.example.Interface", "SomeMethod");
auto method_call = CreateDbusCall();
FakeBluetoothAdvertisementMonitorServiceProviderDelegate delegate;

@ -149,8 +149,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
dbus::MessageReader reader(method_call);
dbus::ObjectPath device_path;
if (!reader.PopObjectPath(&device_path)) {
LOG(WARNING) << "RequestPinCode called with incorrect paramters: "
LOG(WARNING) << "RequestPinCode called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -174,8 +177,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
dbus::ObjectPath device_path;
std::string pincode;
if (!reader.PopObjectPath(&device_path) || !reader.PopString(&pincode)) {
LOG(WARNING) << "DisplayPinCode called with incorrect paramters: "
LOG(WARNING) << "DisplayPinCode called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -194,8 +200,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
dbus::MessageReader reader(method_call);
dbus::ObjectPath device_path;
if (!reader.PopObjectPath(&device_path)) {
LOG(WARNING) << "RequestPasskey called with incorrect paramters: "
LOG(WARNING) << "RequestPasskey called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -221,8 +230,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
uint16_t entered;
if (!reader.PopObjectPath(&device_path) || !reader.PopUint32(&passkey) ||
!reader.PopUint16(&entered)) {
LOG(WARNING) << "DisplayPasskey called with incorrect paramters: "
LOG(WARNING) << "DisplayPasskey called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -244,8 +256,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
dbus::ObjectPath device_path;
uint32_t passkey;
if (!reader.PopObjectPath(&device_path) || !reader.PopUint32(&passkey)) {
LOG(WARNING) << "RequestConfirmation called with incorrect paramters: "
LOG(WARNING) << "RequestConfirmation called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -268,8 +283,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
dbus::MessageReader reader(method_call);
dbus::ObjectPath device_path;
if (!reader.PopObjectPath(&device_path)) {
LOG(WARNING) << "RequestAuthorization called with incorrect paramters: "
LOG(WARNING) << "RequestAuthorization called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -293,8 +311,11 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
dbus::ObjectPath device_path;
std::string uuid;
if (!reader.PopObjectPath(&device_path) || !reader.PopString(&uuid)) {
LOG(WARNING) << "AuthorizeService called with incorrect paramters: "
LOG(WARNING) << "AuthorizeService called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}

@ -109,6 +109,7 @@ class BluetoothAdvertisementServiceProviderImpl
DCHECK(delegate_);
delegate_->Released();
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
// Called by dbus:: when the Bluetooth daemon fetches a single property of

@ -112,8 +112,11 @@ class BluetoothProfileServiceProviderImpl
dbus::MessageReader array_reader(NULL);
if (!reader.PopObjectPath(&device_path) || !reader.PopFileDescriptor(&fd) ||
!reader.PopArray(&array_reader)) {
LOG(WARNING) << "NewConnection called with incorrect paramters: "
LOG(WARNING) << "NewConnection called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}
@ -153,8 +156,11 @@ class BluetoothProfileServiceProviderImpl
dbus::MessageReader reader(method_call);
dbus::ObjectPath device_path;
if (!reader.PopObjectPath(&device_path)) {
LOG(WARNING) << "RequestDisconnection called with incorrect paramters: "
LOG(WARNING) << "RequestDisconnection called with incorrect parameters: "
<< method_call->ToString();
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Incorrect parameters."));
return;
}

@ -690,6 +690,8 @@ void FlossAdapterClient::OnSdpSearchComplete(
for (auto& observer : observers_) {
observer.SdpSearchComplete(device, uuid, sdp_records);
}
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
void FlossAdapterClient::OnSdpRecordCreated(
@ -710,6 +712,8 @@ void FlossAdapterClient::OnSdpRecordCreated(
for (auto& observer : observers_) {
observer.SdpRecordCreated(sdp_record, handle);
}
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call));
}
void FlossAdapterClient::OnDeviceConnected(