aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Lee <cyrus296@gmail.com>2017-07-13 07:47:21 -0700
committerCalvin Lee <cyrus296@gmail.com>2017-07-13 07:47:21 -0700
commit62223e8fbbccac5581da1464081662b44f8a6e03 (patch)
tree3ed23fe4384bbc81e2bd9da71a28264aec0742fd
parent13ed84e8865c02b808444202e6e347d870c5d0e9 (diff)
Don't trust SNI names, fixes #1274
If an item doesn't have a well-formed name, it will not be added to the tray.
-rw-r--r--include/swaybar/tray/sni.h1
-rw-r--r--swaybar/tray/sni.c6
-rw-r--r--swaybar/tray/tray.c14
3 files changed, 16 insertions, 5 deletions
diff --git a/include/swaybar/tray/sni.h b/include/swaybar/tray/sni.h
index 83809b2d..c2544e2a 100644
--- a/include/swaybar/tray/sni.h
+++ b/include/swaybar/tray/sni.h
@@ -28,6 +28,7 @@ void sni_icon_ref_free(struct sni_icon_ref *sni_ref);
/**
* Will return a new item and get its icon. (see warning below)
+ * May return `NULL` if `name` is not valid.
*/
struct StatusNotifierItem *sni_create(const char *name);
diff --git a/swaybar/tray/sni.c b/swaybar/tray/sni.c
index 0c46d5c0..d9a5ca80 100644
--- a/swaybar/tray/sni.c
+++ b/swaybar/tray/sni.c
@@ -413,6 +413,12 @@ static void get_unique_name(struct StatusNotifierItem *item) {
}
struct StatusNotifierItem *sni_create(const char *name) {
+ // Make sure `name` is well formed
+ if (!dbus_validate_bus_name(name, NULL)) {
+ sway_log(L_INFO, "Name (%s) is not a bus name. We cannot create an item.", name);
+ return NULL;
+ }
+
struct StatusNotifierItem *item = malloc(sizeof(struct StatusNotifierItem));
item->name = strdup(name);
item->unique_name = NULL;
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c
index 7634942a..c1d8dde4 100644
--- a/swaybar/tray/tray.c
+++ b/swaybar/tray/tray.c
@@ -90,9 +90,11 @@ static void get_items_reply(DBusPendingCall *pending, void *_data) {
struct StatusNotifierItem *item = sni_create(name);
- sway_log(L_DEBUG, "Item registered with host: %s", name);
- list_add(tray->items, item);
- dirty = true;
+ if (item) {
+ sway_log(L_DEBUG, "Item registered with host: %s", name);
+ list_add(tray->items, item);
+ dirty = true;
+ }
}
bail:
@@ -141,8 +143,10 @@ static DBusHandlerResult signal_handler(DBusConnection *connection,
if (list_seq_find(tray->items, sni_str_cmp, name) == -1) {
struct StatusNotifierItem *item = sni_create(name);
- list_add(tray->items, item);
- dirty = true;
+ if (item) {
+ list_add(tray->items, item);
+ dirty = true;
+ }
}
return DBUS_HANDLER_RESULT_HANDLED;