Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b3c6d1a authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Jakub Pawlowski
Browse files

Store a name string in property without violating string boundaries

Don't copy data beyond end of string when storing it as BT_PROPERTY_BDNAME
in property.
Also, update an unit test to create a string by considering the property
name length.

Test: Running unit tests with ASAN enabled
Change-Id: Iaa586b4a0942f99ba469d1ed963729e7ad721503
parent bb77f6a0
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -219,8 +219,12 @@ static bt_property_t* property_new_(void* val, size_t len,
  bt_property_t* property =
      static_cast<bt_property_t*>(osi_calloc(sizeof(bt_property_t)));

  property->val = osi_malloc(len);
  property->val = osi_calloc(len);
  if (type == BT_PROPERTY_BDNAME) {
    strncpy((char*)property->val, (const char*)val, len);
  } else {
    memcpy(property->val, val, len);
  }

  property->type = type;
  property->len = len;
+2 −1
Original line number Diff line number Diff line
@@ -82,7 +82,8 @@ TEST_F(BluetoothTest, AdapterSetGetName) {
    property_free(new_name);
    new_name = property_new_name("BluetoothTestName2");
  }
  std::string old_name((const char*)property_as_name(name_property)->name);
  std::string old_name((const char*)property_as_name(name_property)->name,
                       name_property->len);

  EXPECT_EQ(bt_interface()->set_adapter_property(new_name), BT_STATUS_SUCCESS);
  semaphore_wait(adapter_properties_callback_sem_);