Skip to content

Commit 00e60e1

Browse files
koffesrlubos
authored andcommitted
Applications: Audio: Resolved coverity issues
- OCT-3180 - Removed all BT_AUDIO_BROADCAST_CODE_SIZE. Ref: zephyrproject-rtos/zephyr#80217 Signed-off-by: Kristoffer Rist Skøien <[email protected]>
1 parent 8db9619 commit 00e60e1

File tree

8 files changed

+22
-13
lines changed

8 files changed

+22
-13
lines changed

applications/nrf5340_audio/src/bluetooth/bt_management/scanning/bt_mgmt_scan_for_broadcast.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static char const *srch_name;
4141
static uint32_t srch_brdcast_id = BRDCAST_ID_NOT_USED;
4242
static struct bt_le_per_adv_sync *pa_sync;
4343
static const struct bt_bap_scan_delegator_recv_state *req_recv_state;
44-
static uint8_t bt_mgmt_broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE];
44+
static uint8_t bt_mgmt_broadcast_code[BT_ISO_BROADCAST_CODE_SIZE];
4545

4646
struct broadcast_source {
4747
char name[BLE_SEARCH_NAME_MAX_LEN];
@@ -363,13 +363,13 @@ static int pa_sync_term_req_cb(struct bt_conn *conn,
363363

364364
static void broadcast_code_cb(struct bt_conn *conn,
365365
const struct bt_bap_scan_delegator_recv_state *recv_state,
366-
const uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE])
366+
const uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE])
367367
{
368368
int ret;
369369
struct bt_mgmt_msg msg;
370370

371371
LOG_DBG("Broadcast code received for %p", (void *)recv_state);
372-
memcpy(bt_mgmt_broadcast_code, broadcast_code, BT_AUDIO_BROADCAST_CODE_SIZE);
372+
memcpy(bt_mgmt_broadcast_code, broadcast_code, BT_ISO_BROADCAST_CODE_SIZE);
373373

374374
msg.event = BT_MGMT_BROADCAST_CODE_RECEIVED;
375375
ret = zbus_chan_pub(&bt_mgmt_chan, &msg, K_NO_WAIT);

applications/nrf5340_audio/src/bluetooth/bt_rendering_and_capture/volume/bt_vol_ctlr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <zephyr/bluetooth/conn.h>
1212
#include <zephyr/bluetooth/audio/vcp.h>
1313

14-
#include "macros_common.h"
15-
1614
#include <zephyr/logging/log.h>
1715
LOG_MODULE_REGISTER(bt_vol_ctlr, CONFIG_BT_VOL_LOG_LEVEL);
1816

applications/nrf5340_audio/src/bluetooth/bt_rendering_and_capture/volume/bt_vol_rend.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <zephyr/bluetooth/conn.h>
1212
#include <zephyr/bluetooth/audio/vcp.h>
1313

14-
#include "macros_common.h"
1514
#include "bt_rendering_and_capture.h"
1615

1716
#include <zephyr/logging/log.h>

applications/nrf5340_audio/src/bluetooth/bt_stream/broadcast/broadcast_sink.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,15 @@ static void base_recv_cb(struct bt_bap_broadcast_sink *sink, const struct bt_bap
446446

447447
if (suitable_stream_found) {
448448
/* Set the initial active stream based on the defined channel of the device */
449-
channel_assignment_get((enum audio_channel *)&active_stream_index);
449+
enum audio_channel audio_channel_temp;
450+
451+
channel_assignment_get(&audio_channel_temp);
452+
if (audio_channel_temp > AUDIO_CH_NUM) {
453+
LOG_ERR("Invalid channel assignment");
454+
return;
455+
}
456+
457+
active_stream_index = (uint8_t)audio_channel_temp;
450458

451459
/** If the stream matching channel is not present, revert back to first BIS, e.g.
452460
* mono stream but channel assignment is RIGHT

applications/nrf5340_audio/src/bluetooth/bt_stream/broadcast/broadcast_source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct broadcast_source_big {
100100
uint8_t num_subgroups;
101101
uint8_t packing;
102102
bool encryption;
103-
uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE + 1];
103+
uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE];
104104
char broadcast_name[BROADCAST_SOURCE_ADV_NAME_MAX + 1];
105105
char adv_name[CONFIG_BT_DEVICE_NAME_MAX + 1];
106106
bool fixed_id;

applications/nrf5340_audio/src/modules/lc3_streamer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct k_work_q lc3_streamer_work_q;
2020

2121
#define LC3_STREAMER_BUFFER_NUM_FRAMES 2
2222

23+
#if CONFIG_SD_CARD_LC3_STREAMER_MAX_NUM_STREAMS > UINT8_MAX
24+
#error "CONFIG_SD_CARD_LC3_STREAMER_MAX_NUM_STREAMS must be less than or equal to UINT8_MAX"
25+
#endif
26+
2327
enum lc3_stream_states {
2428
/* Stream ready to load file and start streaming */
2529
STREAM_IDLE = 0,
@@ -342,7 +346,7 @@ int lc3_streamer_stream_register(const char *const filename, uint8_t *const stre
342346
}
343347

344348
/* Check that there's room for the filename and a NULL terminating char */
345-
if (strlen(filename) > CONFIG_FS_FATFS_MAX_LFN - 1) {
349+
if (strlen(filename) > (ARRAY_SIZE(streams[*streamer_idx].filename) - 1)) {
346350
LOG_ERR("Filename too long");
347351
return -EINVAL;
348352
}
@@ -369,7 +373,7 @@ int lc3_streamer_stream_register(const char *const filename, uint8_t *const stre
369373
return ret;
370374
}
371375

372-
strncpy(streams[*streamer_idx].filename, filename, strlen(filename));
376+
strcpy(streams[*streamer_idx].filename, filename);
373377

374378
ret = data_fifo_init(&streams[*streamer_idx].fifo);
375379
if (ret) {

applications/nrf5340_audio/src/modules/lc3_streamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool lc3_streamer_file_compatible_check(const char *const filename,
6565
*
6666
* @retval 0 Success.
6767
* @retval -EINVAL Invalid filename or streamer_idx.
68-
* @retval -EAGAIN No stream slot is available
68+
* @retval -EAGAIN No stream slot is available.
6969
* @retval -EFAULT Module has not been initialized.
7070
*/
7171
int lc3_streamer_stream_register(const char *const filename, uint8_t *const streamer_idx,

samples/bluetooth/broadcast_config_tool/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,9 +1599,9 @@ static int cmd_encrypt(const struct shell *shell, size_t argc, char **argv)
15991599
return -EINVAL;
16001600
}
16011601

1602-
if (strlen(argv[3]) > BT_AUDIO_BROADCAST_CODE_SIZE) {
1602+
if (strlen(argv[3]) > BT_ISO_BROADCAST_CODE_SIZE) {
16031603
shell_error(shell, "Broadcast code must be %d characters long",
1604-
BT_AUDIO_BROADCAST_CODE_SIZE);
1604+
BT_ISO_BROADCAST_CODE_SIZE);
16051605
return -EINVAL;
16061606
}
16071607
memset(broadcast_param[big_index].broadcast_code, '\0',

0 commit comments

Comments
 (0)