From 4736bc9c52af8332184064a0d7a1eda11b6be699 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jun 2017 22:49:06 +0100 Subject: [PATCH 45/49] bus/containers: Enforce max_containers limit Signed-off-by: Simon McVittie --- bus/containers.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bus/containers.c b/bus/containers.c index 9eb1ed3f..ccd02c07 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -718,6 +718,24 @@ bus_containers_handle_add_container_server (DBusConnection *connection, goto oom; } + limit = bus_context_get_max_containers (context); + + if (_dbus_hash_table_get_n_entries (containers->instances_by_path) >= limit) + { + DBusError local_error = DBUS_ERROR_INIT; + + dbus_set_error (&local_error, DBUS_ERROR_LIMITS_EXCEEDED, + "Connection \"%s\" (%s) is not allowed to create more " + "container servers (max_containers=%d)", + bus_connection_get_name (connection), + bus_connection_get_loginfo (connection), + limit); + bus_context_log_literal (context, DBUS_SYSTEM_LOG_WARNING, + local_error.message); + dbus_move_error (&local_error, error); + goto fail; + } + if (!_dbus_hash_table_insert_string (containers->instances_by_path, instance->path, instance)) goto oom; -- 2.11.0