From 58cd734fdc101b83c4da6b23195b292100f5285f Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 8 Oct 2008 11:21:17 +0200 Subject: Fail cleanly if we don't have knowledge of a connecting device Without this fix we segfault if a device pairs and connects to us before we have completed service discovery to it. Underneath is a more fundamental problem of how we initialize our data structures and this still needs fixing. --- audio/control.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/audio/control.c b/audio/control.c index 2b37fd3f..1dcab3c2 100644 --- a/audio/control.c +++ b/audio/control.c @@ -606,15 +606,18 @@ static void init_uinput(struct avctp *session) debug("AVRCP: uinput initialized for %s", address); } -static void avctp_connect_session(struct avctp *session) +static gboolean avctp_connect_session(struct avctp *session) { GIOChannel *io; gboolean value; - session->state = AVCTP_STATE_CONNECTED; session->dev = manager_find_device(&session->dst, NULL, FALSE); - if (!session->dev) - return; + if (!session->dev) { + error("Connecting audio device not known (SDP not completed)"); + return FALSE; + } + + session->state = AVCTP_STATE_CONNECTED; session->dev->control->session = session; @@ -638,6 +641,8 @@ static void avctp_connect_session(struct avctp *session) G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, (GIOFunc) session_cb, session); g_io_channel_unref(io); + + return TRUE; } static void auth_cb(DBusError *derr, void *user_data) @@ -710,7 +715,8 @@ static void avctp_server_cb(GIOChannel *chan, int err, const bdaddr_t *src, return; proceed: - avctp_connect_session(session); + if (!avctp_connect_session(session)) + goto drop; return; -- cgit