Skip to content

Commit 0b7a335

Browse files
MariuszSkamracarlescufi
authored andcommitted
Bluetooth: ascs: Fix uninitialized stream object
This fixes "Conditional jump or move depends on uninitialised value(s)" error seen in valgrind. The stream object that is allocated by application has to be initialized as it may contain invalid data. Signed-off-by: Mariusz Skamra <[email protected]>
1 parent b546582 commit 0b7a335

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

subsys/bluetooth/audio/ascs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,8 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
15041504

15051505
return err;
15061506
}
1507+
1508+
bt_bap_stream_init(stream);
15071509
}
15081510

15091511
ascs_cp_rsp_success(ASE_ID(ase), BT_ASCS_CONFIG_OP);

subsys/bluetooth/audio/bap_stream.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io,
7878
* CONFIG_BT_BAP_BROADCAST_SINK \
7979
*/
8080

81+
void bt_bap_stream_init(struct bt_bap_stream *stream)
82+
{
83+
struct bt_bap_stream_ops *ops;
84+
void *user_data;
85+
86+
/* Save the stream->ops and stream->user_data owned by API user */
87+
ops = stream->ops;
88+
user_data = stream->user_data;
89+
90+
memset(stream, 0, sizeof(*stream));
91+
92+
/* Restore */
93+
stream->ops = ops;
94+
stream->user_data = user_data;
95+
}
96+
8197
void bt_bap_stream_attach(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep,
8298
struct bt_codec *codec)
8399
{

subsys/bluetooth/audio/bap_stream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* SPDX-License-Identifier: Apache-2.0
88
*/
99

10+
void bt_bap_stream_init(struct bt_bap_stream *stream);
11+
1012
/* Disconnect ISO channel */
1113
int bt_bap_stream_disconnect(struct bt_bap_stream *stream);
1214

0 commit comments

Comments
 (0)