commit ffbf10d07b19a052e2b6d5ef524f7201fe0012c8
parent 1dbc7f7521a66111b3607b60821dac0c4b86602d
Author: Nathan Rossi <nathan@nathanrossi.com>
Date: Thu, 30 Jan 2020 23:50:07 +1000
ipc: Handle unsupported binding event types
Handle binding event types that cannot be encoded gracefully by dropping
the event. This prevents issues for binding types like BINDING_SWITCH,
where the event would cause a crash.
Diffstat:
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
@@ -421,7 +421,8 @@ void ipc_event_binding(struct sway_binding *binding) {
json_object *symbols = json_object_new_array();
json_object *symbol = NULL;
- if (binding->type == BINDING_KEYCODE) { // bindcode: populate input_codes
+ switch (binding->type) {
+ case BINDING_KEYCODE:; // bindcode: populate input_codes
uint32_t keycode;
for (int i = 0; i < binding->keys->length; ++i) {
keycode = *(uint32_t *)binding->keys->items[i];
@@ -430,7 +431,11 @@ void ipc_event_binding(struct sway_binding *binding) {
input_code = keycode;
}
}
- } else { // bindsym/mouse: populate symbols
+ break;
+
+ case BINDING_KEYSYM:
+ case BINDING_MOUSESYM:
+ case BINDING_MOUSECODE:; // bindsym/mouse: populate symbols
uint32_t keysym;
char buffer[64];
for (int i = 0; i < binding->keys->length; ++i) {
@@ -451,6 +456,14 @@ void ipc_event_binding(struct sway_binding *binding) {
json_object_array_add(symbols, str);
}
}
+ break;
+
+ default:
+ sway_log(SWAY_DEBUG, "Unsupported ipc binding event");
+ json_object_put(input_codes);
+ json_object_put(symbols);
+ json_object_put(json_binding);
+ return; // do not send any event
}
json_object_object_add(json_binding, "input_codes", input_codes);