summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Crequy <alban.crequy@collabora.co.uk>2014-07-18 16:45:07 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-09-15 12:30:25 +0100
commit995734750cea65012537748ee56488c707d2f027 (patch)
tree9bb5cf52e57bd4dc508b6732538f4c6dddc3ea4a
parentbbf11cd5f92064c7c8af61ad4d9ff41f3a039abc (diff)
downloaddbus-995734750cea65012537748ee56488c707d2f027.tar.gz
DBusConnection: implements _dbus_connection_get_pending_fds_count
This is one of four commits needed to address CVE-2014-3637. This will allow the bus to know whether there are pending file descriptors in a DBusConnection's DBusMessageLoader. https://bugs.freedesktop.org/show_bug.cgi?id=80559 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> [fix compilation on platforms that do not HAVE_UNIX_FD_PASSING -smcv] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--dbus/dbus-connection-internal.h1
-rw-r--r--dbus/dbus-connection.c11
-rw-r--r--dbus/dbus-message-internal.h1
-rw-r--r--dbus/dbus-message.c15
-rw-r--r--dbus/dbus-transport.c11
-rw-r--r--dbus/dbus-transport.h1
6 files changed, 40 insertions, 0 deletions
diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h
index 2842f2f4..24e47725 100644
--- a/dbus/dbus-connection-internal.h
+++ b/dbus/dbus-connection-internal.h
@@ -100,6 +100,7 @@ void _dbus_connection_test_get_locks (DBusConnectio
DBusMutex **io_path_mutex_loc,
DBusCondVar **dispatch_cond_loc,
DBusCondVar **io_path_cond_loc);
+int _dbus_connection_get_pending_fds_count (DBusConnection *connection);
/* if DBUS_ENABLE_STATS */
void _dbus_connection_get_stats (DBusConnection *connection,
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index f0b6871e..6aa24bc4 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -2549,6 +2549,17 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending)
dbus_pending_call_unref (pending);
}
+/**
+ * Return how many file descriptors are pending in the loader
+ *
+ * @param connection the connection
+ */
+int
+_dbus_connection_get_pending_fds_count (DBusConnection *connection)
+{
+ return _dbus_transport_get_pending_fds_count (connection->transport);
+}
+
/** @} */
/**
diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h
index 5d6594e3..45cb026e 100644
--- a/dbus/dbus-message-internal.h
+++ b/dbus/dbus-message-internal.h
@@ -96,6 +96,7 @@ long _dbus_message_loader_get_max_message_size (DBusMessageLoader
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader,
long n);
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader);
+int _dbus_message_loader_get_pending_fds_count (DBusMessageLoader *loader);
typedef struct DBusInitialFDs DBusInitialFDs;
DBusInitialFDs *_dbus_check_fdleaks_enter (void);
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index f4787b06..59f3bdc8 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -4499,6 +4499,21 @@ _dbus_message_loader_get_max_message_unix_fds (DBusMessageLoader *loader)
return loader->max_message_unix_fds;
}
+/**
+ * Return how many file descriptors are pending in the loader
+ *
+ * @param loader the loader
+ */
+int
+_dbus_message_loader_get_pending_fds_count (DBusMessageLoader *loader)
+{
+#ifdef HAVE_UNIX_FD_PASSING
+ return loader->n_unix_fds;
+#else
+ return 0;
+#endif
+}
+
static DBusDataSlotAllocator slot_allocator =
_DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (message_slots));
diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c
index ecc31827..690e5ba8 100644
--- a/dbus/dbus-transport.c
+++ b/dbus/dbus-transport.c
@@ -1512,6 +1512,17 @@ _dbus_transport_set_allow_anonymous (DBusTransport *transport,
transport->allow_anonymous = value != FALSE;
}
+/**
+ * Return how many file descriptors are pending in the loader
+ *
+ * @param transport the transport
+ */
+int
+_dbus_transport_get_pending_fds_count (DBusTransport *transport)
+{
+ return _dbus_message_loader_get_pending_fds_count (transport->loader);
+}
+
#ifdef DBUS_ENABLE_STATS
void
_dbus_transport_get_stats (DBusTransport *transport,
diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h
index 80fa24ef..ff102f3a 100644
--- a/dbus/dbus-transport.h
+++ b/dbus/dbus-transport.h
@@ -97,6 +97,7 @@ dbus_bool_t _dbus_transport_set_auth_mechanisms (DBusTransport
const char **mechanisms);
void _dbus_transport_set_allow_anonymous (DBusTransport *transport,
dbus_bool_t value);
+int _dbus_transport_get_pending_fds_count (DBusTransport *transport);
/* if DBUS_ENABLE_STATS */
void _dbus_transport_get_stats (DBusTransport *transport,