From 217673fd1c28fcdbdaf0c2fa7e939b3c84c6a22e Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Mon, 11 Jul 2011 17:59:56 +0100 Subject: [PATCH] Prepend eavedrop=true to monitor's filter string This is needed due to FDO#37890, to fix easy eavesdropping and to avoid connection to receive unwanted msg/signals. It also fixes a potential OOM bug. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39140 --- bustle-dbus-monitor.c | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bustle-dbus-monitor.c b/bustle-dbus-monitor.c index 0ebaded..dd70aa7 100644 --- a/bustle-dbus-monitor.c +++ b/bustle-dbus-monitor.c @@ -67,6 +67,8 @@ gettimeofday (struct timeval *__p, #define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu" #define TRAP_NULL_STRING(str) ((str) ? (str) : "") +#define EAVESDROPPING_RULE "eavesdrop=true" + static void print_name_owner_changed (struct timeval *t, const char *name, @@ -209,6 +211,13 @@ print_message_profile (DBusMessage *message) } } +inline static void +oom (const char *doing) +{ + fprintf (stderr, "OOM while %s\n", doing); + exit (1); +} + static DBusHandlerResult profile_filter_func (DBusConnection *connection, DBusMessage *message, @@ -336,11 +345,21 @@ main (int argc, char *argv[]) else if (arg[0] == '-') usage (argv[0], 1); else { - numFilters++; - filters = (char **)realloc(filters, numFilters * sizeof(char *)); - filters[j] = (char *)malloc((strlen(arg) + 1) * sizeof(char *)); - snprintf(filters[j], strlen(arg) + 1, "%s", arg); - j++; + unsigned int filter_len; + numFilters++; + /* Prepend a rule (and a comma) to enable the monitor to eavesdrop. + * Prepending allows the user to add eavesdrop=false at command line + * in order to disable eavesdropping when needed */ + filter_len = strlen (EAVESDROPPING_RULE) + 1 + strlen (arg) + 1; + + filters = (char **) realloc (filters, numFilters * sizeof (char *)); + if (filters == NULL) + oom ("adding a new filter slot"); + filters[j] = (char *) malloc (filter_len * sizeof (char *)); + if (filters[j] == NULL) + oom ("adding a new filter"); + snprintf (filters[j], filter_len, "%s,%s", EAVESDROPPING_RULE, arg); + j++; } } -- 1.7.5.4