From 20807a09b09c19ee1c856f646a96698d3a25eca2 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Thu, 16 Nov 2017 18:00:22 +0100 Subject: [PATCH] Validate closing reasons inside dbus method Also fixes a nice off by one error. According to notification spec, the reason 0 doesn't exist, while the undefined reason wouldn't have been sent. --- src/dbus.c | 6 ++++++ src/dbus.h | 2 ++ src/queues.c | 5 +---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 59c38dc..634355c 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -324,6 +324,12 @@ static void on_get_server_information(GDBusConnection *connection, void notification_closed(notification *n, enum reason reason) { + if (reason < REASON_MIN || REASON_MAX < reason) { + fprintf(stderr, "ERROR: Closing notification with reason '%d' not supported. " + "Closing it with reason '%d'.\n", reason, REASON_UNDEF); + reason = REASON_UNDEF; + } + if (!dbus_conn) { fprintf(stderr, "ERROR: Tried to close notification but dbus connection not set!\n"); return; diff --git a/src/dbus.h b/src/dbus.h index d1a2e22..51fd323 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -6,10 +6,12 @@ #include "notification.h" enum reason { + REASON_MIN = 1, REASON_TIME = 1, REASON_USER = 2, REASON_SIG = 3, REASON_UNDEF = 4, + REASON_MAX = 4, }; int initdbus(void); diff --git a/src/queues.c b/src/queues.c index 2bb05d6..997ab5a 100644 --- a/src/queues.c +++ b/src/queues.c @@ -204,10 +204,7 @@ int queues_notification_close_id(int id, enum reason reason) } if (target) { - - if (reason > 0 && reason < 4) - notification_closed(target, reason); - + notification_closed(target, reason); queues_history_push(target); }