From 12266bf21f6f358787e6bf834691e4a5ca484b37 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jun 2017 22:49:06 +0100 Subject: [PATCH] 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 e7bfcf23..b7bd95d2 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -788,6 +788,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.13.2