]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
bus/containers: Enforce max_containers limit
authorSimon McVittie <smcv@collabora.com>
Thu, 22 Jun 2017 21:49:06 +0000 (22:49 +0100)
committerSimon McVittie <smcv@collabora.com>
Tue, 12 Dec 2017 16:22:35 +0000 (16:22 +0000)
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354

bus/containers.c

index 6095e6713911549180de7bd9bc2f6249122791f2..7aa3e2b7ffea97e95e511bf84c6793b4ff602774 100644 (file)
@@ -798,6 +798,24 @@ bus_containers_handle_add_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;