[pulseaudio-discuss] [PATCH 1/5] bluetooth: don't allow creating transports for invalid devices

Tanu Kaskinen tanuk at iki.fi
Thu Aug 4 17:35:58 UTC 2016


I was working on the bluetooth code, and I wanted to be sure that the
device couldn't be in an invalid state in pa_bluetooth_transport_put().
That made it a bit easier to reason about the code.
---
 src/modules/bluetooth/backend-native.c | 3 +++
 src/modules/bluetooth/backend-ofono.c  | 3 +++
 src/modules/bluetooth/bluez5-util.c    | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index 8d9d95c..c9f0ed4 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -338,6 +338,9 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
     if (d == NULL) {
         pa_log_error("Device doesnt exist for %s", path);
         goto fail;
+    } else if (!d->valid) {
+        pa_log_error("Device %s is invalid.", path);
+        goto fail;
     }
 
     pa_assert_se(dbus_message_iter_next(&arg_i));
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 755df9e..8e43f30 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -251,6 +251,9 @@ static void hf_audio_agent_card_found(pa_bluetooth_backend *backend, const char
     if (!d) {
         pa_log_error("Device doesnt exist for %s", path);
         goto fail;
+    } else if (!d->valid) {
+        pa_log_error("Device %s is invalid.", path);
+        goto fail;
     }
 
     card->transport = pa_bluetooth_transport_new(d, backend->ofono_bus_id, path, PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY, NULL, 0);
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 03c76bf..379a40e 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -136,6 +136,9 @@ pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const
                                                    pa_bluetooth_profile_t p, const uint8_t *config, size_t size) {
     pa_bluetooth_transport *t;
 
+    pa_assert(d);
+    pa_assert(d->valid);
+
     t = pa_xnew0(pa_bluetooth_transport, 1);
     t->device = d;
     t->owner = pa_xstrdup(owner);
-- 
2.8.1



More information about the pulseaudio-discuss mailing list