OSDN Git Service

AVRCP: Reject when CT sends invalid RegisterNotification
authorHansong Zhang <hsz@google.com>
Tue, 10 Jul 2018 19:37:58 +0000 (12:37 -0700)
committerHansong Zhang <hsz@google.com>
Tue, 10 Jul 2018 21:16:20 +0000 (14:16 -0700)
Check whether the RegisterNotification request from CT is valid, and
safely reject invalid request

Bug: 111260441
Test: manually test with RIVA WAND speaker
Change-Id: Ia2edd94e50fa7cb5b61be54f297adf971060a924

packet/tests/avrcp/avrcp_test_packets.h
profile/avrcp/device.cc
profile/avrcp/tests/avrcp_device_test.cc

index 304c43a..13994d0 100644 (file)
@@ -105,6 +105,10 @@ std::vector<uint8_t> register_volume_changed_notification = {
     0x03, 0x48, 0x00, 0x00, 0x19, 0x58, 0x31, 0x00,
     0x00, 0x05, 0x0d, 0x00, 0x00, 0x00, 0x00};
 
+// AVRCP Register Notification without any parameter
+std::vector<uint8_t> register_notification_invalid = {
+    0x03, 0x48, 0x00, 0x00, 0x19, 0x58, 0x31, 0x00, 0x00, 0x05};
+
 // AVRCP Interim Playback Status Notification
 std::vector<uint8_t> interim_play_status_notification = {
     0x0f, 0x48, 0x00, 0x00, 0x19, 0x58, 0x31, 0x00, 0x00, 0x02, 0x01, 0x00};
index efe6d27..8efadc8 100644 (file)
@@ -189,6 +189,14 @@ void Device::HandleGetCapabilities(
 
 void Device::HandleNotification(
     uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt) {
+  if (!pkt->IsValid()) {
+    DEVICE_LOG(ERROR) << __func__ << ": Request packet is not valid";
+    auto response = RejectBuilder::MakeBuilder(pkt->GetCommandPdu(),
+                                               Status::INVALID_PARAMETER);
+    send_message(label, false, std::move(response));
+    return;
+  }
+
   DEVICE_VLOG(4) << __func__ << ": event=" << pkt->GetEventRegistered();
 
   switch (pkt->GetEventRegistered()) {
index 12c36c2..56f03e4 100644 (file)
@@ -1048,6 +1048,22 @@ TEST_F(AvrcpDeviceTest, getInvalidItemAttributesTest) {
   SendBrowseMessage(1, request);
 }
 
+TEST_F(AvrcpDeviceTest, invalidRegisterNotificationTest) {
+  MockMediaInterface interface;
+  NiceMock<MockA2dpInterface> a2dp_interface;
+
+  test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);
+
+  auto reg_notif_rej_rsp = RejectBuilder::MakeBuilder(
+      CommandPdu::REGISTER_NOTIFICATION, Status::INVALID_PARAMETER);
+  EXPECT_CALL(response_cb,
+              Call(1, false, matchPacket(std::move(reg_notif_rej_rsp))))
+      .Times(1);
+
+  auto reg_notif_request = TestAvrcpPacket::Make(register_notification_invalid);
+  SendMessage(1, reg_notif_request);
+}
+
 }  // namespace avrcp
 }  // namespace bluetooth