summaryrefslogtreecommitdiff
path: root/src/profile.c
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@gmail.com>2021-06-10 19:06:49 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-07-01 15:49:45 -0700
commit33b9f85dac12bfaf718f6cd030ef6eff5102ebd8 (patch)
treea020981617c6633a737c0fe34d7f4be17e21caa1 /src/profile.c
parent77dba3b4d9b09fd9085b2945710ef46455c1842a (diff)
downloadbluez-33b9f85dac12bfaf718f6cd030ef6eff5102ebd8.tar.gz
profile: Fail RegisterProfile if UUID already exists
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
Diffstat (limited to 'src/profile.c')
-rw-r--r--src/profile.c30
1 files changed, 30 insertions, 0 deletions
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);