From d0b2a395fb4f313ab3657f61522fb309849b5044 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2014 19:19:16 +0000 Subject: [PATCH 06/13] Log when we exceed max_match_rules_per_connection --- bus/driver.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/bus/driver.c b/bus/driver.c index 2d06abc..39157bd 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1312,6 +1312,7 @@ bus_driver_handle_add_match (DBusConnection *connection, const char *text, *bustype; DBusString str; BusMatchmaker *matchmaker; + int limit; BusContext *context; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -1319,15 +1320,25 @@ bus_driver_handle_add_match (DBusConnection *connection, text = NULL; rule = NULL; - if (bus_connection_get_n_match_rules (connection) >= - bus_context_get_max_match_rules_per_connection (bus_transaction_get_context (transaction))) + context = bus_transaction_get_context (transaction); + limit = bus_context_get_max_match_rules_per_connection (context); + + if (bus_connection_get_n_match_rules (connection) >= limit) { - dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED, + DBusError tmp_error; + + dbus_error_init (&tmp_error); + dbus_set_error (&tmp_error, DBUS_ERROR_LIMITS_EXCEEDED, "Connection \"%s\" is not allowed to add more match rules " - "(increase limits in configuration file if required)", + "(increase limits in configuration file if required; " + "max_match_rules_per_connection=%d)", bus_connection_is_active (connection) ? bus_connection_get_name (connection) : - "(inactive)"); + "(inactive)", + limit); + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, "%s", + tmp_error.message); + dbus_move_error (&tmp_error, error); goto failed; } @@ -1345,7 +1356,6 @@ bus_driver_handle_add_match (DBusConnection *connection, if (rule == NULL) goto failed; - context = bus_transaction_get_context (transaction); bustype = context ? bus_context_get_type (context) : NULL; if (bus_match_rule_get_client_is_eavesdropping (rule) && !bus_apparmor_allows_eavesdropping (connection, bustype, error)) -- 2.8.1