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

Commit a22694cc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check a2dp packet length is zero" into qt-qpr1-dev-plus-aosp

parents e4606e3a 30290de9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -80,6 +80,10 @@
    {
      "name" : "net_test_btif_rc",
      "host" : true
    },
    {
      "name" : "net_test_stack_a2dp_native",
      "host" : true
    }
  ]
}
+33 −0
Original line number Diff line number Diff line
@@ -467,3 +467,36 @@ cc_test {
        cfi: false,
    },
}

cc_test {
    name: "net_test_stack_a2dp_native",
    defaults: ["fluoride_defaults"],
    test_suites: ["device-tests"],
    host_supported: true,
    include_dirs: [
        "external/libldac/inc",
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    srcs: [
        "test/a2dp/a2dp_vendor_ldac_decoder_test.cc",
        "test/a2dp/misc_fake.cc",
    ],
    shared_libs: [
        "libcrypto",
        "libcutils",
        "libprotobuf-cpp-lite",
    ],
    static_libs: [
        "libbt-common",
        "libbt-protos-lite",
        "liblog",
        "libosi",
        "libosi-AllocationTestHarness",
    ],
    sanitize: {
        address: true,
        cfi: true,
        misc_undefined: ["bounds"],
    },
}
+9 −0
Original line number Diff line number Diff line
@@ -203,10 +203,19 @@ void a2dp_vendor_ldac_decoder_cleanup(void) {

bool a2dp_vendor_ldac_decoder_decode_packet(BT_HDR* p_buf) {
  pthread_mutex_lock(&(a2dp_ldac_decoder_cb.mutex));
  if (p_buf == nullptr) {
    LOG_ERROR("%s Dropping packet with nullptr", __func__);
    return false;
  }
  unsigned char* pBuffer =
      reinterpret_cast<unsigned char*>(p_buf->data + p_buf->offset);
  //  unsigned int bufferSize = p_buf->len;
  unsigned int bytesValid = p_buf->len;
  if (bytesValid == 0) {
    LOG_WARN("%s Dropping packet with zero length", __func__);
    return false;
  }

  LDACBT_SMPL_FMT_T fmt;
  int bs_bytes, frame_number;

+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ extern "C" {
#endif /* LDAC_BCO_API */

/* This file contains the definitions, declarations and macros for an
 * implimentation of LDAC buffer control operation.
 * implementation of LDAC buffer control operation.
 */

#define LDAC_BCO_ERR_NONE 0
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <base/logging.h>
#include <gtest/gtest.h>
#include <stdio.h>
#include <cstdint>

#include "stack/include/ldacBT_bco_for_fluoride.h"

#include "osi/test/AllocationTestHarness.h"
#undef LOG_TAG
#include "stack/a2dp/a2dp_vendor_ldac_decoder.cc"

extern void allocation_tracker_uninit(void);
namespace {

uint8_t* Data(BT_HDR* packet) { return packet->data + packet->offset; }

}  // namespace

/**
 * Test class to test selected functionality in stack/a2dp
 */
class A2dpStackTest : public AllocationTestHarness {
 protected:
  void SetUp() override {
    AllocationTestHarness::SetUp();
    // Disable our allocation tracker to allow ASAN full range
    allocation_tracker_uninit();
  }

  void TearDown() override { AllocationTestHarness::TearDown(); }

  BT_HDR* AllocateL2capPacket(const std::vector<uint8_t> data) const {
    auto packet = AllocatePacket(data.size());
    std::copy(data.cbegin(), data.cend(), Data(packet));
    return packet;
  }

 private:
  BT_HDR* AllocatePacket(size_t packet_length) const {
    BT_HDR* packet =
        static_cast<BT_HDR*>(osi_calloc(sizeof(BT_HDR) + packet_length));
    packet->len = packet_length;
    return packet;
  }
};

TEST_F(A2dpStackTest, DecodePacket_ZeroLength) {
  const std::vector<uint8_t> data;
  BT_HDR* p_buf = AllocateL2capPacket(data);
  CHECK(!a2dp_vendor_ldac_decoder_decode_packet(p_buf));
  osi_free(p_buf);
}
Loading