Merge branch 'bugfix/fix_bt_coverity' into 'master'

bugfix: Fix array compared against 0 in btc_manage.c and the issue of uninitialized pointer reading in coexist_printf

Closes IDF-13868

See merge request espressif/esp-idf!41455
This commit is contained in:
Wang Meng Yang
2025-09-17 11:03:30 +08:00
2 changed files with 17 additions and 14 deletions

View File

@@ -8,19 +8,20 @@
#include "btc/btc_task.h" #include "btc/btc_task.h"
#include "osi/thread.h" #include "osi/thread.h"
#if BTC_DYNAMIC_MEMORY == FALSE #if BTC_DYNAMIC_MEMORY == TRUE
void *btc_profile_cb_tab[BTC_PID_NUM] = {};
#else
void **btc_profile_cb_tab; void **btc_profile_cb_tab;
#else
void *btc_profile_cb_tab[BTC_PID_NUM] = {};
#endif #endif
void esp_profile_cb_reset(void) void esp_profile_cb_reset(void)
{ {
#if BTC_DYNAMIC_MEMORY == TRUE #if BTC_DYNAMIC_MEMORY == TRUE
if (btc_profile_cb_tab == NULL) { void *p = btc_profile_cb_tab;
if (p == NULL) {
return; return;
} }
#endif #endif
int i; int i;
@@ -31,11 +32,12 @@ void esp_profile_cb_reset(void)
int btc_profile_cb_set(btc_pid_t profile_id, void *cb) int btc_profile_cb_set(btc_pid_t profile_id, void *cb)
{ {
#if BTC_DYNAMIC_MEMORY == TRUE #if BTC_DYNAMIC_MEMORY == TRUE
if (btc_profile_cb_tab == NULL) { void *p = btc_profile_cb_tab;
if (p == NULL) {
return -1; return -1;
} }
#endif #endif
if (profile_id < 0 || profile_id >= BTC_PID_NUM) { if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
return -1; return -1;
@@ -48,11 +50,12 @@ int btc_profile_cb_set(btc_pid_t profile_id, void *cb)
void *btc_profile_cb_get(btc_pid_t profile_id) void *btc_profile_cb_get(btc_pid_t profile_id)
{ {
#if BTC_DYNAMIC_MEMORY == TRUE #if BTC_DYNAMIC_MEMORY == TRUE
if (btc_profile_cb_tab == NULL) { void *p = btc_profile_cb_tab;
if (p == NULL) {
return NULL; return NULL;
} }
#endif #endif
if (profile_id < 0 || profile_id >= BTC_PID_NUM) { if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
return NULL; return NULL;

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2016-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -44,7 +44,7 @@ static int lib_printf(const char* tag, const char* format, va_list arg)
int coexist_printf(const char* format, ...) int coexist_printf(const char* format, ...)
{ {
va_list arg; va_list arg = {};
va_start(arg, format); va_start(arg, format);
int res = lib_printf("coexist", format, arg); int res = lib_printf("coexist", format, arg);
va_end(arg); va_end(arg);