2018-04-20 11:02:38

by Szymon Janc

[permalink] [raw]
Subject: [PATCH] adapter: Fix accessing NULL adv_manager

adv_manager might be NULL also if BR/EDR only mdoe is set in main.conf
or if btd_adv_manager_new failed so checking for LE in supported
settings is not enough. This also makes btd_adv_manager_refresh
consistent with other adv_manager API regarding passing NULL manager
as function parameter.
---
src/adapter.c | 3 +--
src/advertising.c | 3 +++
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f91b04173..932b2a34d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -540,8 +540,7 @@ static void settings_changed(struct btd_adapter *adapter, uint32_t settings)
g_dbus_emit_property_changed(dbus_conn, adapter->path,
ADAPTER_INTERFACE, "Discoverable");
store_adapter_info(adapter);
- if (adapter->supported_settings & MGMT_SETTING_LE)
- btd_adv_manager_refresh(adapter->adv_manager);
+ btd_adv_manager_refresh(adapter->adv_manager);
}

if (changed_mask & MGMT_SETTING_BONDABLE) {
diff --git a/src/advertising.c b/src/advertising.c
index b976562c4..0cb6eac3a 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -1173,6 +1173,9 @@ void btd_adv_manager_destroy(struct btd_adv_manager *manager)

void btd_adv_manager_refresh(struct btd_adv_manager *manager)
{
+ if (!manager)
+ return;
+
queue_foreach(manager->clients, (queue_foreach_func_t)refresh_adv,
NULL);
}
--
2.14.3



2018-04-20 11:37:07

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH] adapter: Fix accessing NULL adv_manager

On Friday, 20 April 2018 13:02:38 CEST Szymon Janc wrote:
> adv_manager might be NULL also if BR/EDR only mdoe is set in main.conf
> or if btd_adv_manager_new failed so checking for LE in supported
> settings is not enough. This also makes btd_adv_manager_refresh
> consistent with other adv_manager API regarding passing NULL manager
> as function parameter.
> ---
> src/adapter.c | 3 +--
> src/advertising.c | 3 +++
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index f91b04173..932b2a34d 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -540,8 +540,7 @@ static void settings_changed(struct btd_adapter
> *adapter, uint32_t settings) g_dbus_emit_property_changed(dbus_conn,
> adapter->path,
> ADAPTER_INTERFACE, "Discoverable");
> store_adapter_info(adapter);
> - if (adapter->supported_settings & MGMT_SETTING_LE)
> - btd_adv_manager_refresh(adapter->adv_manager);
> + btd_adv_manager_refresh(adapter->adv_manager);
> }
>
> if (changed_mask & MGMT_SETTING_BONDABLE) {
> diff --git a/src/advertising.c b/src/advertising.c
> index b976562c4..0cb6eac3a 100644
> --- a/src/advertising.c
> +++ b/src/advertising.c
> @@ -1173,6 +1173,9 @@ void btd_adv_manager_destroy(struct btd_adv_manager
> *manager)
>
> void btd_adv_manager_refresh(struct btd_adv_manager *manager)
> {
> + if (!manager)
> + return;
> +
> queue_foreach(manager->clients, (queue_foreach_func_t)refresh_adv,
> NULL);
> }

Applied.

--
pozdrawiam
Szymon Janc