From af52ab51274c3ccf52e03b05102d4308d09e631c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jun 2017 12:50:48 +0100 Subject: [PATCH] bus/containers: Enforce max_connections_per_container Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354 --- bus/containers.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bus/containers.c b/bus/containers.c index 7bff2ce3..740e8f15 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -473,6 +473,19 @@ new_connection_cb (DBusServer *server, void *data) { BusContainerInstance *instance = data; + int limit = bus_context_get_max_connections_per_container (instance->context); + + /* This is O(n), but we assume n is small in practice. */ + if (_dbus_list_get_length (&instance->connections) >= limit) + { + /* We can't send this error to the new connection, so just log it */ + bus_context_log (instance->context, DBUS_SYSTEM_LOG_WARNING, + "Closing connection to container server " + "%s (%s \"%s\") because it would exceed resource limit " + "(max_connections_per_container=%d)", + instance->path, instance->type, instance->name, limit); + return; + } if (!dbus_connection_set_data (new_connection, contained_data_slot, bus_container_instance_ref (instance), -- 2.13.3