mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04:00
make sure we never access an invalid pa_bluetooth_device object
This commit is contained in:
parent
1c8f968282
commit
90fbc036f4
1 changed files with 19 additions and 17 deletions
|
|
@ -132,7 +132,7 @@ struct userdata {
|
||||||
|
|
||||||
char *address;
|
char *address;
|
||||||
char *path;
|
char *path;
|
||||||
const pa_bluetooth_device* device;
|
pa_bluetooth_discovery *discovery;
|
||||||
|
|
||||||
pa_dbus_connection *connection;
|
pa_dbus_connection *connection;
|
||||||
|
|
||||||
|
|
@ -1728,6 +1728,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
|
||||||
struct userdata *u;
|
struct userdata *u;
|
||||||
enum profile *d;
|
enum profile *d;
|
||||||
pa_queue *inputs = NULL, *outputs = NULL;
|
pa_queue *inputs = NULL, *outputs = NULL;
|
||||||
|
const pa_bluetooth_device *device;
|
||||||
|
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
pa_assert(new_profile);
|
pa_assert(new_profile);
|
||||||
|
|
@ -1735,11 +1736,16 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
|
||||||
|
|
||||||
d = PA_CARD_PROFILE_DATA(new_profile);
|
d = PA_CARD_PROFILE_DATA(new_profile);
|
||||||
|
|
||||||
if (u->device->headset_state < PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_HSP) {
|
if (!(device = pa_bluetooth_discovery_get_by_path(u->discovery, u->path))) {
|
||||||
|
pa_log_error("Failed to get device object.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device->headset_state != PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_HSP) {
|
||||||
pa_log_warn("HSP is not connected, refused to switch profile");
|
pa_log_warn("HSP is not connected, refused to switch profile");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (u->device->audio_sink_state < PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_A2DP) {
|
else if (device->audio_sink_state != PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_A2DP) {
|
||||||
pa_log_warn("A2DP is not connected, refused to switch profile");
|
pa_log_warn("A2DP is not connected, refused to switch profile");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -1884,11 +1890,10 @@ static int add_card(struct userdata *u, const char *default_profile, const pa_bl
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const pa_bluetooth_device* find_device(struct userdata *u, pa_bluetooth_discovery *y, const char *address, const char *path) {
|
static const pa_bluetooth_device* find_device(struct userdata *u, const char *address, const char *path) {
|
||||||
const pa_bluetooth_device *d = NULL;
|
const pa_bluetooth_device *d = NULL;
|
||||||
|
|
||||||
pa_assert(u);
|
pa_assert(u);
|
||||||
pa_assert(y);
|
|
||||||
|
|
||||||
if (!address && !path) {
|
if (!address && !path) {
|
||||||
pa_log_error("Failed to get device address/path from module arguments.");
|
pa_log_error("Failed to get device address/path from module arguments.");
|
||||||
|
|
@ -1896,7 +1901,7 @@ static const pa_bluetooth_device* find_device(struct userdata *u, pa_bluetooth_d
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
if (!(d = pa_bluetooth_discovery_get_by_path(y, path))) {
|
if (!(d = pa_bluetooth_discovery_get_by_path(u->discovery, path))) {
|
||||||
pa_log_error("%s is not a valid BlueZ audio device.", path);
|
pa_log_error("%s is not a valid BlueZ audio device.", path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1907,7 +1912,7 @@ static const pa_bluetooth_device* find_device(struct userdata *u, pa_bluetooth_d
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!(d = pa_bluetooth_discovery_get_by_address(y, address))) {
|
if (!(d = pa_bluetooth_discovery_get_by_address(u->discovery, address))) {
|
||||||
pa_log_error("%s is not known.", address);
|
pa_log_error("%s is not known.", address);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1942,9 +1947,9 @@ int pa__init(pa_module* m) {
|
||||||
uint32_t channels;
|
uint32_t channels;
|
||||||
struct userdata *u;
|
struct userdata *u;
|
||||||
const char *address, *path;
|
const char *address, *path;
|
||||||
pa_bluetooth_discovery *y = NULL;
|
|
||||||
DBusError err;
|
DBusError err;
|
||||||
char *mike, *speaker;
|
char *mike, *speaker;
|
||||||
|
const pa_bluetooth_device *device;
|
||||||
|
|
||||||
pa_assert(m);
|
pa_assert(m);
|
||||||
|
|
||||||
|
|
@ -1999,19 +2004,16 @@ int pa__init(pa_module* m) {
|
||||||
if (setup_dbus(u) < 0)
|
if (setup_dbus(u) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(y = pa_bluetooth_discovery_get(m->core)))
|
if (!(u->discovery = pa_bluetooth_discovery_get(m->core)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(u->device = find_device(u, y, address, path))) /* should discovery ref be kept? */
|
if (!(device = find_device(u, address, path)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* Add the card structure. This will also initialize the default profile */
|
/* Add the card structure. This will also initialize the default profile */
|
||||||
if (add_card(u, pa_modargs_get_value(ma, "profile", NULL), u->device) < 0)
|
if (add_card(u, pa_modargs_get_value(ma, "profile", NULL), device) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
pa_bluetooth_discovery_unref(y);
|
|
||||||
y = NULL;
|
|
||||||
|
|
||||||
/* Connect to the BT service and query capabilities */
|
/* Connect to the BT service and query capabilities */
|
||||||
if (init_bt(u) < 0)
|
if (init_bt(u) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
@ -2052,9 +2054,6 @@ int pa__init(pa_module* m) {
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
if (y)
|
|
||||||
pa_bluetooth_discovery_unref(y);
|
|
||||||
|
|
||||||
pa__done(m);
|
pa__done(m);
|
||||||
|
|
||||||
dbus_error_free(&err);
|
dbus_error_free(&err);
|
||||||
|
|
@ -2135,5 +2134,8 @@ void pa__done(pa_module *m) {
|
||||||
pa_xfree(u->address);
|
pa_xfree(u->address);
|
||||||
pa_xfree(u->path);
|
pa_xfree(u->path);
|
||||||
|
|
||||||
|
if (u->discovery)
|
||||||
|
pa_bluetooth_discovery_unref(u->discovery);
|
||||||
|
|
||||||
pa_xfree(u);
|
pa_xfree(u);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue