linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel Šimko" <daniel@simko.xyz>
To: linux-bluetooth@vger.kernel.org
Cc: "Daniel Šimko" <daniel@simko.xyz>
Subject: [PATCH BlueZ] profiles: Fix segfault when using headset controls
Date: Sat, 10 Oct 2020 22:27:28 +0000 (UTC)	[thread overview]
Message-ID: <20201010222719.439956-1-daniel@simko.xyz> (raw)

This fixes a segmentation fault caused by controls trying to notify an
unregistered player.

When an unregistered player is replaced by another valid player from the
list, the session is not referenced in the sessions list of the player
and when this player is unregistered, its reference is not removed from
the session.
---
 profiles/audio/avrcp.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index ed436de3b..70f52efe8 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -4441,8 +4441,19 @@ void avrcp_unregister_player(struct avrcp_player *player)
 		if (target == NULL)
 			continue;
 
-		if (target->player == player)
-			target->player = g_slist_nth_data(server->players, 0);
+		if (target->player == player) {
+			struct avrcp_player *next_player = g_slist_nth_data(
+								server->players,
+								0);
+
+			target->player = next_player;
+
+			if (next_player) {
+				next_player->sessions = g_slist_append(
+							next_player->sessions,
+							session);
+			}
+		}
 	}
 
 	avrcp_player_event(player,
-- 
2.28.0


             reply	other threads:[~2020-10-10 23:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-10 22:27 Daniel Šimko [this message]
2020-10-10 23:33 ` [BlueZ] profiles: Fix segfault when using headset controls bluez.test.bot
2020-10-12 17:26   ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201010222719.439956-1-daniel@simko.xyz \
    --to=daniel@simko.xyz \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).