OSDN Git Service

obexd: Fix not checking for valid fd on NewConnection
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 6 Jun 2013 08:05:46 +0000 (15:05 +0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 11 Jun 2013 21:12:33 +0000 (00:12 +0300)
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

index 07baf90..e4d518e 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <inttypes.h>
+#include <fcntl.h>
 #include <sys/socket.h>
 
 #include <glib.h>
@@ -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);