From 16f059c6c3c2cc9f00c97d64254a491cff0a7672 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 3 Feb 2015 14:45:37 +0000 Subject: [PATCH 6/8] Capture a fake reply if a broadcast cannot be delivered --- bus/connection.c | 2 +- bus/connection.h | 3 +++ bus/dispatch.c | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index 6b18f6f..fbd0307 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -2180,7 +2180,7 @@ out: return ret; } -static dbus_bool_t +dbus_bool_t bus_transaction_capture_error_reply (BusTransaction *transaction, const DBusError *error, DBusMessage *in_reply_to) diff --git a/bus/connection.h b/bus/connection.h index 280fbf1..dca2263 100644 --- a/bus/connection.h +++ b/bus/connection.h @@ -134,6 +134,9 @@ dbus_bool_t bus_transaction_send (BusTransaction * dbus_bool_t bus_transaction_capture (BusTransaction *transaction, DBusConnection *connection, DBusMessage *message); +dbus_bool_t bus_transaction_capture_error_reply (BusTransaction *transaction, + const DBusError *error, + DBusMessage *in_reply_to); dbus_bool_t bus_transaction_send_from_driver (BusTransaction *transaction, DBusConnection *connection, DBusMessage *message); diff --git a/bus/dispatch.c b/bus/dispatch.c index 630f814..5cb9d6f 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -63,17 +63,47 @@ send_one_message (DBusConnection *connection, BusTransaction *transaction, DBusError *error) { + DBusError stack_error = DBUS_ERROR_INIT; + if (!bus_context_check_security_policy (context, transaction, sender, addressed_recipient, connection, message, - NULL)) - return TRUE; /* silently don't send it */ + &stack_error)) + { + if (!bus_transaction_capture_error_reply (transaction, &stack_error, + message)) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "broadcast rejected, but not enough " + "memory to tell monitors"); + } + + dbus_error_free (&stack_error); + return TRUE; /* don't send it but don't return an error either */ + } if (dbus_message_contains_unix_fds(message) && !dbus_connection_can_send_type(connection, DBUS_TYPE_UNIX_FD)) - return TRUE; /* silently don't send it */ + { + dbus_set_error (&stack_error, DBUS_ERROR_NOT_SUPPORTED, + "broadcast cannot be delivered to %s (%s) because " + "it does not support receiving Unix fds", + bus_connection_get_name (connection), + bus_connection_get_loginfo (connection)); + + if (!bus_transaction_capture_error_reply (transaction, &stack_error, + message)) + { + bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, + "broadcast with Unix fd not delivered, but not " + "enough memory to tell monitors"); + } + + dbus_error_free (&stack_error); + return TRUE; /* don't send it but don't return an error either */ + } if (!bus_transaction_send (transaction, connection, -- 2.1.4