diff --git a/sway/commands.c b/sway/commands.c index dee03d71..8d199467 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -121,6 +121,9 @@ void input_cmd_apply(struct input_config *input) { for (int i = 0; i < input_devices->length; ++i) { device = input_devices->items[i]; char* dev_identifier = libinput_dev_unique_id(device); + if (!dev_identifier) { + break; + } int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0; free(dev_identifier); if (match) { diff --git a/sway/extensions.c b/sway/extensions.c index 96c7e60d..759cbb84 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -81,6 +81,10 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc } sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output); struct background_config *config = malloc(sizeof(struct background_config)); + if (!config) { + sway_log(L_ERROR, "Unable to allocate background config"); + return; + } config->client = client; config->output = output; config->surface = wlc_resource_from_wl_surface_resource(surface); diff --git a/sway/handlers.c b/sway/handlers.c index 23a994b4..3abe2fca 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -123,6 +123,11 @@ static void update_background_geometries(wlc_handle output) { static bool handle_input_created(struct libinput_device *device) { const char *identifier = libinput_dev_unique_id(device); + if (!identifier) { + sway_log(L_ERROR, "Unable to allocate unique name for input device %p", + device); + return true; + } sway_log(L_INFO, "Found input device (%s)", identifier); list_add(input_devices, device); @@ -402,6 +407,10 @@ static bool handle_view_created(wlc_handle handle) { } else { swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); wlc_handle *h = malloc(sizeof(wlc_handle)); + if (!h) { + sway_log(L_ERROR, "Unable to allocate window handle, view handler bailing out"); + return true; + } *h = handle; sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged); list_add(output->unmanaged, h); diff --git a/sway/input.c b/sway/input.c index acd69a6b..61757ab8 100644 --- a/sway/input.c +++ b/sway/input.c @@ -45,6 +45,10 @@ char *libinput_dev_unique_id(struct libinput_device *device) { int len = strlen(name) + sizeof(char) * 6; char *identifier = malloc(len); + if (!identifier) { + sway_log(L_ERROR, "Unable to allocate unique input device name"); + return NULL; + } const char *fmt = "%d:%d:%s"; snprintf(identifier, len, fmt, vendor, product, name); diff --git a/sway/ipc-server.c b/sway/ipc-server.c index de72beca..ba0cb310 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -414,7 +414,11 @@ void ipc_client_handle_command(struct ipc_client *client) { struct libinput_device *device = input_devices->items[i]; char* identifier = libinput_dev_unique_id(device); json_object *device_object = json_object_new_object(); - json_object_object_add(device_object, "identifier", json_object_new_string(identifier)); + if (!identifier) { + json_object_object_add(device_object, "identifier", NULL); + } else { + json_object_object_add(device_object, "identifier", json_object_new_string(identifier)); + } json_object_array_add(inputs, device_object); free(identifier); }