From d75a747a3ddc99f258025a923de1cf4821bf3115 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 15 Dec 2016 17:52:53 -0500 Subject: Handle config-related allocation failures --- sway/handlers.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 86a976d8..23a994b4 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -571,6 +571,10 @@ static void handle_binding_command(struct sway_binding *binding) { // binding since it will be gone after the reload has completed. if (strcasecmp(binding->command, "reload") == 0) { binding_copy = sway_binding_dup(binding); + if (!binding_copy) { + sway_log(L_ERROR, "Unable to duplicate binding during reload"); + return; + } reload = true; } -- cgit v1.2.3 From 8cef81d6f23adb66873ee5fd84aa7180b22624f2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 15 Dec 2016 18:03:59 -0500 Subject: Handle some more memory allocation failures --- sway/commands.c | 3 +++ sway/extensions.c | 4 ++++ sway/handlers.c | 9 +++++++++ sway/input.c | 4 ++++ sway/ipc-server.c | 6 +++++- 5 files changed, 25 insertions(+), 1 deletion(-) (limited to 'sway/handlers.c') 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); } -- cgit v1.2.3