linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcin Zawiejski <dragmz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: SEGFAULT in obexd manager.c:find_session
Date: Sun, 30 Dec 2012 14:18:05 +0100	[thread overview]
Message-ID: <50E03F0D.6020605@gmail.com> (raw)

Hi, I think there is a bug in obexd in manager.c:find_session function.

What happens here is a segfault when manager.c:find_session calls 
g_str_equal(obc_session_get_path(session), path). This is caused by the 
sessions list having a session with a NULL path.

Basically when I call manager.c:create_session, the session created 
there is added to sessions list but it has a NULL path until the 
manager.c:create_callback is called.

However the manager.c:create_callback is not called at all if the remote 
device refuses the connection. So when manager.c:find_session is called, 
it actually calls the g_str_equal(NULL, path) causing the segfault.

This might be simply fixed by modifying the manager.c:find_session to 
check for a NULL session path before calling g_str_equal(...).

The problem is reproducible by having two sessions, with one awaiting 
connection and another one with an active file transfer. When the file 
transfer errors and I call org.bluez.obex.Client1 RemoveSession then the 
obexd segfaults since the session awaiting connection has a NULL path.

I'm not sure if the session with a NULL path should be on the sessions 
list or not. If its okay, then here's a simple patch for the 
manager.c:find_session function:

---
diff --git a/obexd/client/manager.c b/obexd/client/manager.c
index 8f62a30..28b890c 100644
--- a/obexd/client/manager.c
+++ b/obexd/client/manager.c
@@ -142,8 +142,9 @@ static struct obc_session *find_session(const char 
*path)

         for (l = sessions; l; l = l->next) {
                 struct obc_session *session = l->data;
+               const char *session_path = obc_session_get_path(session);

-               if (g_str_equal(obc_session_get_path(session), path) == 
TRUE)
+               if (session_path != NULL && g_str_equal(session_path, 
path) == TRUE)
                         return session;
         }
---

Marcin.

             reply	other threads:[~2012-12-30 13:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-30 13:18 Marcin Zawiejski [this message]
2012-12-30 14:28 ` SEGFAULT in obexd manager.c:find_session Luiz Augusto von Dentz
2012-12-30 23:58   ` Marcin Zawiejski
2012-12-31 10:13     ` Luiz Augusto von Dentz
2012-12-31  0:01   ` Marcin Zawiejski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50E03F0D.6020605@gmail.com \
    --to=dragmz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).