aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-07-13 20:24:33 -0700
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-07-13 20:57:23 -0700
commit5ceb52962e76b600396e356e31ec93edf8046475 (patch)
tree0fd4687209366697336ad541928e6b11dfe4bca2 /swaybar
parentMerge pull request #1276 from 4e554c4c/bad_items (diff)
downloadsway-5ceb52962e76b600396e356e31ec93edf8046475.tar.gz
sway-5ceb52962e76b600396e356e31ec93edf8046475.tar.zst
sway-5ceb52962e76b600396e356e31ec93edf8046475.zip
Fix name validation in sni_watcher.c
This commit also fixes a memory leak that occurs on failure.
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/tray/sni_watcher.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/swaybar/tray/sni_watcher.c b/swaybar/tray/sni_watcher.c
index 388e181d..86453e70 100644
--- a/swaybar/tray/sni_watcher.c
+++ b/swaybar/tray/sni_watcher.c
@@ -150,10 +150,14 @@ static void register_item(DBusConnection *connection, DBusMessage *message) {
150 sway_log(L_ERROR, "Error parsing method args: %s\n", error.message); 150 sway_log(L_ERROR, "Error parsing method args: %s\n", error.message);
151 } 151 }
152 152
153 name = strdup(name);
154 sway_log(L_INFO, "RegisterStatusNotifierItem called with \"%s\"\n", name); 153 sway_log(L_INFO, "RegisterStatusNotifierItem called with \"%s\"\n", name);
155 154
156 // Don't add duplicate or not real item 155 // Don't add duplicate or not real item
156 if (!dbus_validate_bus_name(name, NULL)) {
157 sway_log(L_INFO, "This item is not valid, we cannot keep track of it.");
158 return;
159 }
160
157 if (list_seq_find(items, (int (*)(const void *, const void *))strcmp, name) != -1) { 161 if (list_seq_find(items, (int (*)(const void *, const void *))strcmp, name) != -1) {
158 return; 162 return;
159 } 163 }
@@ -161,7 +165,7 @@ static void register_item(DBusConnection *connection, DBusMessage *message) {
161 return; 165 return;
162 } 166 }
163 167
164 list_add(items, name); 168 list_add(items, strdup(name));
165 item_registered_signal(connection, name); 169 item_registered_signal(connection, name);
166 170
167 // It's silly, but xembedsniproxy wants a reply for this function 171 // It's silly, but xembedsniproxy wants a reply for this function
@@ -184,6 +188,12 @@ static void register_host(DBusConnection *connection, DBusMessage *message) {
184 sway_log(L_INFO, "RegisterStatusNotifierHost called with \"%s\"\n", name); 188 sway_log(L_INFO, "RegisterStatusNotifierHost called with \"%s\"\n", name);
185 189
186 // Don't add duplicate or not real host 190 // Don't add duplicate or not real host
191 if (!dbus_validate_bus_name(name, NULL)) {
192 sway_log(L_INFO, "This item is not valid, we cannot keep track of it.");
193 return;
194 }
195
196
187 if (list_seq_find(hosts, (int (*)(const void *, const void *))strcmp, name) != -1) { 197 if (list_seq_find(hosts, (int (*)(const void *, const void *))strcmp, name) != -1) {
188 return; 198 return;
189 } 199 }