mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 16:01:27 +00:00
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.
This commit is contained in:
parent
13ed84e886
commit
62223e8fbb
|
@ -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)
|
* 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);
|
struct StatusNotifierItem *sni_create(const char *name);
|
||||||
|
|
||||||
|
|
|
@ -413,6 +413,12 @@ static void get_unique_name(struct StatusNotifierItem *item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StatusNotifierItem *sni_create(const char *name) {
|
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));
|
struct StatusNotifierItem *item = malloc(sizeof(struct StatusNotifierItem));
|
||||||
item->name = strdup(name);
|
item->name = strdup(name);
|
||||||
item->unique_name = NULL;
|
item->unique_name = NULL;
|
||||||
|
|
|
@ -90,10 +90,12 @@ static void get_items_reply(DBusPendingCall *pending, void *_data) {
|
||||||
|
|
||||||
struct StatusNotifierItem *item = sni_create(name);
|
struct StatusNotifierItem *item = sni_create(name);
|
||||||
|
|
||||||
|
if (item) {
|
||||||
sway_log(L_DEBUG, "Item registered with host: %s", name);
|
sway_log(L_DEBUG, "Item registered with host: %s", name);
|
||||||
list_add(tray->items, item);
|
list_add(tray->items, item);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
@ -141,9 +143,11 @@ static DBusHandlerResult signal_handler(DBusConnection *connection,
|
||||||
if (list_seq_find(tray->items, sni_str_cmp, name) == -1) {
|
if (list_seq_find(tray->items, sni_str_cmp, name) == -1) {
|
||||||
struct StatusNotifierItem *item = sni_create(name);
|
struct StatusNotifierItem *item = sni_create(name);
|
||||||
|
|
||||||
|
if (item) {
|
||||||
list_add(tray->items, item);
|
list_add(tray->items, item);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return DBUS_HANDLER_RESULT_HANDLED;
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
} else if (dbus_message_is_signal(message, "org.freedesktop.StatusNotifierWatcher",
|
} else if (dbus_message_is_signal(message, "org.freedesktop.StatusNotifierWatcher",
|
||||||
|
|
Loading…
Reference in a new issue