From 9ee1038cff9e9e3eaa637df94704801cf09cbe66 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 6 Jun 2013 15:05:46 +0700 Subject: [PATCH] obexd: Fix not checking for valid fd on NewConnection The fd needs to be checked as it may not be valid which cause the following warnings: ==8162== Warning: invalid file descriptor 1031 in syscall fcntl(DUPFD_CLOEXEC)() (obexd:8162): GLib-WARNING **: giounix.c:412Error while getting flags for FD: Bad file descriptor (9) --- obexd/plugins/bluetooth.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c index 07baf9058..e4d518ef5 100644 --- a/obexd/plugins/bluetooth.c +++ b/obexd/plugins/bluetooth.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -132,6 +133,18 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, dbus_message_iter_get_basic(&args, &fd); + if (fd < 0) { + error("bluetooth: NewConnection invalid fd"); + return invalid_args(msg); + } + + /* Read fd flags to make sure it can be used */ + if (fcntl(fd, F_GETFD) < 0) { + error("bluetooth: fcntl(%d, F_GETFD): %s (%d)", fd, + strerror(errno), errno); + return invalid_args(msg); + } + io = g_io_channel_unix_new(fd); if (io == NULL) return invalid_args(msg); -- 2.11.0