linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "João Paulo Rechi Vita" <jprvita@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: jprvita@endlessos.org, jprvita@gmail.com, linux@endlessos.org
Subject: [PATCH BlueZ] profile: Fail RegisterProfile if UUID already exists
Date: Thu, 10 Jun 2021 19:07:28 -0700	[thread overview]
Message-ID: <20210611020728.15233-1-jprvita@endlessos.org> (raw)

From: João Paulo Rechi Vita <jprvita@gmail.com>

If a process tries to register a profile implementation that is already
registered, RegisterProfile should fail.

This should help address issues when two instances of PulseAudio are
running at the same time, and the second instance tries to register an
audio profile implementation that has already been registered by the
first instance. Two situations where this may happen is when more than
one user is logged in, or during the transition between the GDM session
and the user session, when PulseAudio gets started on the new session
before the old session has been fully terminated.

https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/303
https://gitlab.gnome.org/GNOME/gdm/-/issues/486
---
 src/profile.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/profile.c b/src/profile.c
index 5e460b639..60d17b6ae 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -749,6 +749,30 @@ void btd_profile_foreach(void (*func)(struct btd_profile *p, void *data),
 	}
 }
 
+static struct btd_profile *btd_profile_find_uuid(const char *uuid)
+{
+	GSList *l, *next;
+
+	for (l = profiles; l != NULL; l = next) {
+		struct btd_profile *p = l->data;
+
+		if (!g_strcmp0(p->local_uuid, uuid))
+			return p;
+		next = g_slist_next(l);
+	}
+
+	for (l = ext_profiles; l != NULL; l = next) {
+		struct ext_profile *ext = l->data;
+		struct btd_profile *p = &ext->p;
+
+		if (!g_strcmp0(p->local_uuid, uuid))
+			return p;
+		next = g_slist_next(l);
+	}
+
+	return NULL;
+}
+
 int btd_profile_register(struct btd_profile *profile)
 {
 	profiles = g_slist_append(profiles, profile);
@@ -2441,6 +2465,12 @@ static DBusMessage *register_profile(DBusConnection *conn,
 	dbus_message_iter_get_basic(&args, &uuid);
 	dbus_message_iter_next(&args);
 
+	if (btd_profile_find_uuid(uuid)) {
+		warn("%s tried to register %s which is already registered",
+								sender, uuid);
+		return btd_error_not_permitted(msg, "UUID already registered");
+	}
+
 	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY)
 		return btd_error_invalid_args(msg);
 
-- 
2.20.1


             reply	other threads:[~2021-06-11  2:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  2:07 João Paulo Rechi Vita [this message]
2021-06-11  2:43 ` [BlueZ] profile: Fail RegisterProfile if UUID already exists bluez.test.bot
2021-06-29 23:46 ` [PATCH BlueZ] " João Paulo Rechi Vita
2021-07-01 22:50   ` Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2021-06-11  2:06 João Paulo Rechi Vita

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=20210611020728.15233-1-jprvita@endlessos.org \
    --to=jprvita@gmail.com \
    --cc=jprvita@endlessos.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux@endlessos.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).