2013-12-02 15:46:25

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 1/4] android/socket: Cleanup sockets on unregister

From: Andrei Emeltchenko <[email protected]>

This cleans up rfsock structures closing all sockets and making general cleanup
for servers and for connections. This will be called form socket unregister.
---
android/socket.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/android/socket.c b/android/socket.c
index 76b40c8..4502e90 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -93,8 +93,10 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
return rfsock;
}

-static void cleanup_rfsock(struct rfcomm_sock *rfsock)
+static void cleanup_rfsock(gpointer data)
{
+ struct rfcomm_sock *rfsock = data;
+
DBG("rfsock: %p fd %d real_sock %d chan %u",
rfsock, rfsock->fd, rfsock->real_sock, rfsock->channel);

@@ -936,5 +938,8 @@ void bt_socket_unregister(void)
{
DBG("");

+ g_list_free_full(connections, cleanup_rfsock);
+ g_list_free_full(servers, cleanup_rfsock);
+
ipc_unregister(HAL_SERVICE_ID_SOCK);
}
--
1.8.3.2



2013-12-02 15:46:26

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 2/4] android/a2dp: Fix possible NULL dereference

From: Andrei Emeltchenko <[email protected]>

Since a2dp_record may return NULL, check return value. This
silences static analysers tools.
---
android/a2dp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/android/a2dp.c b/android/a2dp.c
index 98c138e..324a211 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -366,9 +366,10 @@ bool bt_a2dp_register(const bdaddr_t *addr)
}

rec = a2dp_record();
- if (bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
+ if (!rec || bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
error("Failed to register on A2DP record");
- sdp_record_free(rec);
+ if (rec)
+ sdp_record_free(rec);
g_io_channel_shutdown(server, TRUE, NULL);
g_io_channel_unref(server);
server = NULL;
--
1.8.3.2


2013-12-02 15:46:27

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 3/4] android/pan: Remove unneeded NULL assignment

From: Andrei Emeltchenko <[email protected]>

---
android/pan.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/android/pan.c b/android/pan.c
index 3270aa4..8e719b2 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -81,7 +81,6 @@ static void pan_device_free(struct pan_device *dev)

devices = g_slist_remove(devices, dev);
g_free(dev);
- dev = NULL;
}

static void bt_pan_notify_conn_state(struct pan_device *dev, uint8_t state)
--
1.8.3.2


2013-12-02 15:46:28

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 4/4] android/pan: Fix no return on error path

From: Andrei Emeltchenko <[email protected]>

This fixes possible crash in case connect fails.
---
android/pan.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/android/pan.c b/android/pan.c
index 8e719b2..1c1015a 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -172,6 +172,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer data)
error("%s", err->message);
bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
pan_device_free(dev);
+ return;
}

src = (local_role == HAL_PAN_ROLE_NAP) ? BNEP_SVC_NAP : BNEP_SVC_PANU;
--
1.8.3.2