From: Luiz Augusto von Dentz Date: Thu, 6 Jun 2013 08:05:46 +0000 (+0700) Subject: obexd: Fix not checking for valid fd on NewConnection X-Git-Tag: android-x86-4.4-r3~7998 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9ee1038cff9e9e3eaa637df94704801cf09cbe66;p=android-x86%2Fexternal-bluetooth-bluez.git 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) --- 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);