shared/bap: Protect bap_stream_notify_connecting
Luiz Augusto von Dentz
maintainerPATCH v3 5/5 shared/bap: Protect bap_stream_notify_connecting
From: Luiz Augusto von Dentz <[email protected]>
bap_stream_notify_connecting may encounter callbacks that remove itself while traversing the state_cbs, so this attempts to prevent to cause a crash by prefetching the next entry.
--- src/shared/bap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
src/shared/bap.c +6 -2
@@ -3036,10 +3036,14 @@ static void bap_stream_notify_connecting(struct bt_bap_stream *stream, {const struct queue_entry *entry; -for (entry =queue_get_entries (stream->bap->state_cbs); entry; - entry = entry->next) { +for (entry =queue_get_entries (stream->bap->state_cbs); entry;) {struct bt_bap_state *state = entry->data; +/* Prefetch next entry since the callback may remove the current +* entry. +*/ + entry = entry->next; +if (state->connecting) state->connecting (stream, connecting, fd, state->data); }
Signature · 1 line
2.54.0